+ Reply to Thread
Results 1 to 8 of 8

Making Rows Relative in VBA

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Making Rows Relative in VBA

    I'm using the following code on the worksheet to allow specified rows to be shown/hidden when a specified cell is double clicked. The problem I have is that new rows are constantly being inserted into the sheet which then throws all the cell and row references out.

    How can I make these relative references, so that if new rows are inserted anywhere in the sheet, all the references in the code update accordingly to reflect their new position?

    Please Login or Register  to view this content.
    Many thanks

  2. #2
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Making Rows Relative in VBA

    Use Named_Ranges in place of Rows(Whatever)...

  3. #3
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Making Rows Relative in VBA

    Hi hafizimran,

    Okay, I'll give that a go, but how about for the Target Address?

  4. #4
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Making Rows Relative in VBA

    So, I tried it with Named Ranges at it doesn't appear to work.

    Is there another solution to this problem that might work?

  5. #5
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Making Rows Relative in VBA

    Though I'm problably doing it wrong. Is anyone able to help. I've attached a simple example. I need to be able to insert rows and for the Target address and row references to be relative so that they still work when news rows are intserted anywhere within the sheet.

    I'm still very new to VBA, so my knowledge is a bit lacking.

    Many thanks
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Making Rows Relative in VBA

    Here is your file with altered code.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Making Rows Relative in VBA

    Hi hafizimran,

    That works perfectly, many thanks. Is there a way to expand on that to allow the worksheet to be protected, so that when the user double clicks on the specified cell, the sheet unlocks to show the relevant rows and once shown, the sheet locks again and then the same when the user wants to hide the rows by double clicking the cell?

    Many thanks

  8. #8
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Making Rows Relative in VBA

    Yes... Add code to unprotect and protect sheet before and after the code like this:

    Please Login or Register  to view this content.

+ 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