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

button hideshow rows

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

Button to hide/show rows

ResolvedVersion 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:

Using Excel's MODE function

Use Excel's MODE function to display the most common value present in a particular range of cells.

The Mode function looks like this:

=MODE(cell range)

As an example, if 35 is the most commonly recurring number in a particular cell range, then the function will display 35.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.