Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Bryant Smith   on Jan 30 In MS Office Category.

  
Question Answered By: Victoria Hughes   on Jan 30

I'm not sure what the PURPOSE of your macro is, so here's some
possibilities:

Keep in mind that the Cells format is:
Cells(row,column),
so C5 is cells(5,3)

now, it looks like your script is simply to select a
set of rows, not necessarily those in the range.
Let's say I have a Range(A8:D20) named  "TestRange".
But only have Data in A8-A14.

The UsedRange.Rows.Count method actually returns the row
number of the last cell with content (row 14).
But your .Select statement can select any number of cells,
independent on the Named Range, say: from row 2 thru lastrow,
which is more than the range, and does not have to even include
the range  itself. Like:

lastrow = ActiveSheet.UsedRange.Rows.Count
With Worksheets(ActiveSheet.Name)
.Range(Cells(2, 7), Cells(lastrow, 17)).Select
End With

Of course, if you already know the column LETTERS, you could use:

lastrow = ActiveSheet.UsedRange.Rows.Count
With Worksheets(ActiveSheet.Name)
.Range("G2:Q" & lastrow).Select
End With

If your intent is to actually select the named range,
then you can simply use:

Range("TestRange").Select

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on highlight a range using a named range Or get search suggestion and latest updates.


Tagged: