Toggle Button to Hide/Unhide Rows

Don.Inc

New Member
Joined
Apr 29, 2011
Messages
2
Hi. My first question is as above. I've looked all around the forum for codes and have found many but me being such an excel noob I don't know how to adapt them to my situation.
What I need is the code for a toggle Button that:
~When the toggle button is in its enabled unhides rows 15-58 and says "Hide"
~When the toggle button is dis-enabled (unpressed) hide rows 15-58 and says "Unhide"
Thank you guys in advanced, as you can tell I haven't got much excel experience.
P.S This is Excel from MS Office '07
Cheers
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello,

Welcome to the Board!

This uses a toggle button named togglebutton1.

Right click the activeX toggle button while in design mode. Select veiw code. Then paste in:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ToggleButton1_Click()<br><br><SPAN style="color:#00007F">If</SPAN> ToggleButton1 <SPAN style="color:#00007F">Then</SPAN><br>    MsgBox "Hide."<br>    Rows("15:58").EntireRow.Hidden = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">Else</SPAN><br>    MsgBox "Unhide."<br>    Rows("15:58").EntireRow.Hidden = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

See if that does the task.
 
Upvote 0
If you assign this macro to a forms command button or any shape, this will do what you want.
Code:
Sub toggleRows()
    Dim toggleRows As Range
    Set toggleRows = Sheet1.Range("15:58").EntireRow
    
    With toggleRows
        .Hidden = Not (.Rows(1).Hidden)
    
        If TypeName(Application.Caller) = "String" Then
            ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text = IIf(.Hidden, "Show", "Hide")
        End If
    
    End With
End Sub
 
Last edited:
Upvote 0
Hello,

Welcome to the Board!

This uses a toggle button named togglebutton1.

Right click the activeX toggle button while in design mode. Select veiw code. Then paste in:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ToggleButton1_Click()<br><br><SPAN style="color:#00007F">If</SPAN> ToggleButton1 <SPAN style="color:#00007F">Then</SPAN><br>****MsgBox "Hide."<br>****Rows("15:58").EntireRow.Hidden = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">Else</SPAN><br>****MsgBox "Unhide."<br>****Rows("15:58").EntireRow.Hidden = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

See if that does the task.

Cheers worked a charm.
 
Upvote 0
For the Forms Command Button that Mike posted the code to, how could that be modified for columns?? Example: I only need to hide and unhide column C

Sub toggleRows()
Dim toggleRows As Range
Set toggleRows = Sheet1.Range("15:58").EntireRow

With toggleRows
.Hidden = Not (.Rows(1).Hidden)

If TypeName(Application.Caller) = "String" Then
ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text = IIf(.Hidden, "Show", "Hide")
End If

End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top