+ Reply to Thread
Results 1 to 5 of 5

Select range dynamically using relative row and column references

  1. #1
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Select range dynamically using relative row and column references

    Hi,

    I am looking for some help with VBA syntax to select a range dynamically.

    I have included an example in the attached workbook to help explain the problem. This is part of a bigger project.

    Essentially, when a name is selected (using SelName), I want to select the range of cells on the selected row that correspond to the CurrentMonth and EndMonth columns.

    In other parts of the project, I have been able to select fixed ranges no problem using a combination of Offset and Resize.

    However, in this case, the selection needs to work dynamically (especially becuase the CurrentMonth won't be fixed in practice - it will roll forward each month).

    I have been experimenting with .column and .row but without any success.

    If someone can help me get the syntax right, I would be most grateful.


    gtol
    Attached Files Attached Files
    Last edited by gtol; 03-01-2012 at 06:46 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Select range dynamically using relative row and column references

    Hi,

    Does this do what you need?

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Select range dynamically using relative row and column references

    Hi Sweep,

    Thanks for the quick reply !

    Your code works a treat. I changed the address of CurrentMonth and it still picks up the correct range.

    I can see that you are adding the value of the home column (2) to the value of the CurrentMonth to get the starting position of the dynamic range which makes sense.

    Just an observation - I was half expecting a solution that referenced Range("CurrentMonth").column or something similar as the stating position. Is there a reason why you decided to work with the 'value' rather than the 'column' of the range ?

    gtol

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Select range dynamically using relative row and column references

    Just an observation - I was half expecting a solution that referenced Range("CurrentMonth").column or something similar as the stating position. Is there a reason why you decided to work with the 'value' rather than the 'column' of the range ?
    Yup - mainly because I like to overcomplicate things. You're quite right of course, this makes much more sense!!

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Select range dynamically using relative row and column references

    Hi Sweep,

    That is EXACTLY what I was looking for and, now that i see the syntax, it makes perfect sense.
    I can use this gem in lots of parts of my project.

    Thanks a million !

    gtol

+ 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