+ Reply to Thread
Results 1 to 5 of 5

Relative Locations

  1. #1
    Registered User
    Join Date
    03-16-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2011
    Posts
    4

    Relative Locations

    I'm making a price-estimating sheet for our office. So far I've got everything working the way I want. The sheet takes up cells A1 through O23. Various drop-down lists within the estimator trigger certain macros to run, changing other areas of the sheet.

    My question is what is the best way to reference certain cells in the sheet without referring directly to their address? The reason for this is that I am planning on duplicating the exact same section multiple times on one sheet, with each one acting independently from the other.

    So for instance, pushing the reset button should only effect the region from A1 to O23. If I have a duplicate of A1:O23 below in the area A24:O66, and I push its reset button, again, it should only effect A24:066. The same goes for selecting other portions of the list.

    I can make this work by writing massive code and very repetitive code specifying certain ranges and such, but for cleanliness, I want code that can work for as many duplicates as I want.

    Hopefully I've been somewhat clear on this. I've posted a couple of screen shots aswell,

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Relative Locations

    jamgood96,

    Try this bit of code for each button:

    Please Login or Register  to view this content.


    Hope this helps,
    ~tigeravatar

  3. #3
    Registered User
    Join Date
    03-16-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2011
    Posts
    4

    Re: Relative Locations

    Great, I'll play around with that some. I did notice that it is still reliant upon calling the range A1:023. So if I have a similar setup below that range, I'll have to have a separate piece of code for that range, correct?

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Relative Locations

    jamgood96,

    You would only need to specifically designate different ranges if the area below the first one (A1:023) is of a different size. If its the same size (uses columns A to O and rows 1 to 23) then the macro will find the appropriate range for you.

    What the macro does is get the address of the TopLeftCell that the button clicked is touching. It then goes through each area of size identical to A1:O23 (checks that first, then checks A24:O46, etc) and sets the area to the one that contains the address of that TopLeftCell.

    Hope that helps,
    ~tigeravatar

  5. #5
    Registered User
    Join Date
    03-16-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2011
    Posts
    4

    Re: Relative Locations

    Quote Originally Posted by tigeravatar View Post
    jamgood96,

    You would only need to specifically designate different ranges if the area below the first one (A1:023) is of a different size. If its the same size (uses columns A to O and rows 1 to 23) then the macro will find the appropriate range for you.

    What the macro does is get the address of the TopLeftCell that the button clicked is touching. It then goes through each area of size identical to A1:O23 (checks that first, then checks A24:O46, etc) and sets the area to the one that contains the address of that TopLeftCell.

    Hope that helps,
    ~tigeravatar
    Ok, great. I think that makes sense.

    Along with the reset button, I have other functions reliant upon certain areas of the range. For instance, I need a macro to execute if any cells within range B3:B13 change. Of course, I would like to reuse this same macro in the duplicate below for ranges B36:B46.

+ 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