×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Cell selection by macro

Cell selection by macro

Cell selection by macro

(OP)
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.

RE: Cell selection by macro

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

RE: Cell selection by macro

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.

RE: Cell selection by macro

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources