I have a simple toggle macro that hides/unhides portions of the sheet when activated. I am not using Excel's built-in toggle button for this; I am just using a standard button. To get the toggle functionality, I have several of these statements within the macro:
Range("NamedRange1").EntireRow.Hidden = Not Range("NamedRange1").EntireRow.Hidden
This works fine as long as the button and the named range are on the same sheet. However, I cannot get it to work if the range to hide/unhide is on a different sheet from where the button is located. I have tried this code, but it doesn't work:
Worksheets("[Sheet Name]").Range("NamedRange2").EntireRow.Hidden = Not Worksheets("[Sheet Name]").Range("NamedRange2").EntireRow.Hidden
What am I doing wrong?
Bookmarks