button hideshow rows

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Button to hide/show rows

Button to hide/show rows

resolvedResolved · 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

RE: Button to hide/show rows

Thats brilliant thank you very much for your time.

Tom

 

Training courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Moving or Copying Sheets Between Workbooks in Excel 2010

Here's how to move or copy sheets between workbooks in Excel 2010:

Open the sheet you want to move or copy then on the Ribbon click the Home tab. Click Format. Under Organize Sheets, select the option Move or Copy Sheet and then choose where you want the sheet to be moved/copied to.

View all Excel hints and tips


Server loaded in 0.08 secs.