+ Reply to Thread
Results 1 to 4 of 4

For Each rCell Query

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    424

    For Each rCell Query

    Hi,

    I have a piece of code which looks like this

    For Each rCell In Range("A2:AF300").Rows
    Is it possible to change it so that the start point is A2 but the end point is the last row containing data? The last column will still be AF but the row will be variable.

    Thanks

    Tim.
    Last edited by timbo1957; 10-18-2011 at 05:57 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,997

    Re: For Each rCell Query

    Assuming column A always has data for each row:
    For Each rCell In Range("A2:AF" & cells(rows.count, "A").end(xlup).row).Rows
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Valued Forum Contributor
    Join Date
    11-15-2007
    Location
    England
    MS-Off Ver
    Office Pro Plus 2021
    Posts
    424

    Re: For Each rCell Query

    Thanks romperstomper, just what I needed.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: For Each rCell Query

    Hello,

    find the last row with code like

    dim rCell as range
    dim lrow as long
    lrow = cells(rows.count, "A").end(xlup).row
    for each rCell in Range("A2:AF" & lrow)
       ' do something
    next rCell
    cheers,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1