98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Button to hide/show rows
Button to hide/show rows
Resolved · Low Priority · Version 2007
Tom has attended:
Excel VBA Intro Intermediate course
Access Intermediate course
Button to hide/show rows
Hi,
I am looking to create a button that hides certain rows at the first click and then shows them again on the next click, I thought this would do it (partly taken from a recorded macro) but it only hides the rows and then does nothing. Thanks very much...
Sub Hide_Previous_Working_Week()
' Hides the previous working week table
If Rows("30:53").Hidden Then
Rows("30:53").Select
Selection.EntireRow.Hidden = False
Else
Rows("31:52").Select
Selection.EntireRow.Hidden = True
End If
End Sub
RE: Button to hide/show rows
Hi Tom
Thanks for your question
Your problem was that when the rows were hidden, you were trying to select them, and this was causing problems. Fortunately, this is not necessary.
I have rewritten the code thus:
Sub Hide_Previous_Working_Week()
' Hides the previous working week table
If Rows("30:53").Hidden Then
Rows("30:53").EntireRow.Hidden = False
Else
Rows("30:53").EntireRow.Hidden = True
End If
End Sub
and it now works
Regards
Stephen
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Moving or Copying Sheets Between Workbooks in Excel 2010Here's how to move or copy sheets between workbooks in Excel 2010: |