+ Reply to Thread
Results 1 to 7 of 7

macro that hides a row referenced in a cell, instead of just the row indicated by the cell

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    West Virginia
    MS-Off Ver
    Excel 2010
    Posts
    9

    macro that hides a row referenced in a cell, instead of just the row indicated by the cell

    Hello and I am new to VBA, so thorough answers are appreciated. I have tried searching for help, but am not sure what to search for. A spreadsheet with full code is attached.

    I have 6 buttons attached to 6 macros that each hide a row or rows when clicked. However, the row numbers I need to hide keep changing, so hard coding the row number into my macro is not working. I want to make my spreadsheet a little more useful and have the range in the macro reference the value of the cell in the formula For example, cell "A4" in the example below has the value of 14 on the attached file. I want row #14 hidden, not row #4 which will be hidden according to the code as written, but I can't find a way to make that work. The next time I update the worksheet, cell A4 might have the value of 22, so I would want row #22 hiden in that instance, but whatever the row, the macro needs to point to cell A4 in order to figure out the row assignment.

    Sub HideChartRow4Toggle()

    Set myRng = Range("A4") '***I want the code to hide the row referenced in cell A4, not row 4, but do not know how to name the range correctly***
    myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)

    End Sub

    Also, is there a way to make the button display a name (hide, unhide) to indicate what will happen if you click it?
    Thank you greatly,
    Susan
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: macro that hides a row referenced in a cell, instead of just the row indicated by the

    hi susanbarbour, welcome to Excelforum,

    Please Login or Register  to view this content.
    PS. You need to use code tags when posting VB code

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: macro that hides a row referenced in a cell, instead of just the row indicated by the

    codes for buttons (top to bottom) basing on the sample sheet provided:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-11-2012
    Location
    West Virginia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: macro that hides a row referenced in a cell, instead of just the row indicated by the

    Watersev,
    Thank you! I spent the better part of this week working on my little piece of code & searching forums (again, new at this). How do you unhide using your code?

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: macro that hides a row referenced in a cell, instead of just the row indicated by the

    for button_one:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-11-2012
    Location
    West Virginia
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: macro that hides a row referenced in a cell, instead of just the row indicated by the

    Ah - okay, thanks!

  7. #7
    Registered User
    Join Date
    06-04-2010
    Location
    Baku
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: macro that hides a row referenced in a cell, instead of just the row indicated by the

    Formula: copy to clipboard
    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)

Tags for this Thread

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