Good morning everyone
I need a button which, when clicked will hide rows 6&7. Also when its clicked the caption needs to change to 'Show Examples'.
After the rows have been hidden, when the button is clicked again the rows must become visible and the caption change back to 'Hide Examples'.
Obviously this should be looped so it can be clicked unlimited times.
Any ideas?
Hi twofootgiant,
Try this code:
Private Sub btn1_Click() Select Case btn1.Caption Case "Hide Examples" Range("A6").EntireRow.Hidden = True Range("A7").EntireRow.Hidden = True btn1.Caption = "Show Examples" Case "Show Examples" Range("A6").EntireRow.Hidden = False Range("A7").EntireRow.Hidden = False btn1.Caption = "Hide Examples" End Select End Sub
There are only 10 types of people in the world:
Those who understand binary, and those who don't!
Iv sorted it using:
Its just the caption changing bit I need now :DIf Rows("6:7").EntireRow.Hidden = False Then Rows("6:7").EntireRow.Hidden = True Else Rows("6:7").EntireRow.Hidden = False End If
You can use this peice of code:
just change btn1 to the button name and then the text after the = that you want it to say (but the code i posted i think would be more simple to amend in the future and potensionally give less space for error)btn1.Caption =
There are only 10 types of people in the world:
Those who understand binary, and those who don't!
thanks..That works perfectly
No problem, glad i could help![]()
There are only 10 types of people in the world:
Those who understand binary, and those who don't!
This is a bit shorter
Option Explicit Private Sub btn1_Click() Rows("6:7").EntireRow.Hidden = Not Rows("6:7").EntireRow.Hidden Select Case btn1.Caption Case "Show Examples": btn1.Caption = "Hide Examples" Case "Hide Examples": btn1.Caption = "Show Examples" End Select End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks