Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cell selection by macro

Status
Not open for further replies.

bpeirson

Structural
Apr 7, 2003
147
I have a macro which selectas a predefined set of rows on a worksheet. I would like to know how to have this macro select only those rows appearing above the first empty row or above the row with a certain value in column A.

Any tips are appreciated.
 
Replies continue below

Recommended for you

Try the following, this looks at cell D4 for a value and then looks down column A for the first occurence and selects all the rows above.

targetvalue = Cells(1, 4).Value
endrow = Columns("A:A").Find(targetvalue).Row
Rows("1:" & endrow).Select
 
If you define a name (Ctrl-F3), for example MyRange, as:
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A))
MyRange will always refer to the filled cells from A1 downwards, and you can refer directly to it in VB, by
Range("MyRange").Select
See other threads in this forum, and John Walkenbach's site (and many others) for dynamic named ranges (that is what MyRange is in this example).
Good luck!

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Thanks, I was somewhat on track with ab123456's solution but I couldn't figure out the specific syntax of the Rows("1:" & endrow).

I just recently started working with named ranges. The dynamic named range is new to me, looks like a powerful tool, thanks joerd.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor