+ Reply to Thread
Results 1 to 5 of 5

VBA Range navigation

  1. #1
    Registered User
    Join Date
    07-30-2011
    Location
    Miami, FL
    MS-Off Ver
    Excel 2007
    Posts
    2

    VBA Range navigation

    Hello,

    I have a VBA macro that selects a range (A part if a column of data) and then looks into the range for a specific value. the problem is How do I select the 4th value down in the column

    I am only familiar with the For each loop used to traverse a range, how do I go directly to a cell within a range (based on relative reference)?

    Thanks,

    Steve

  2. #2
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: VBA Range navigation

    Try
    Please Login or Register  to view this content.

  3. #3
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: VBA Range navigation

    Welcome to the forum, Steve.

    The range class has an Offset property which has this syntax:
    Offset( [RowOffset] , [ColumnOffset] )


    so, once you've found the anchor cell, you can find the cell 4 rows down like this:
    Please Login or Register  to view this content.
    The 0 is optional - I included it for clarity.


    One thing to note is that Offset returns a range with the same dimensions as the anchor range:
    Please Login or Register  to view this content.

    Another way to do it is with the Cells property which has this (simplified) syntax:
    Cells( [RowIndex] , [ColumnIndex] )

    Please Login or Register  to view this content.
    Note that the cells property will always only return a single cell (this is one thing that differentiates it from the Offset property):
    Please Login or Register  to view this content.
    Hope that helps,

    Colin

    RAD Excel Blog

  4. #4
    Registered User
    Join Date
    07-30-2011
    Location
    Miami, FL
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VBA Range navigation

    Thanks for the explanation. Very thorough - I need to review it to see how it will work for me in my code. The offset seems to be most useful when a single cell is identified (Which is exactly what I have.)

    Steve

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Range navigation

    Are you sure that you need a Loop, also it's generally unnecesssary to select a range in VBA.

    Maybe a better explanation of what you are doing & posting your code will get you better code.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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