This is my first try at any code for Excel, so bear with me. It's probably not the best, but working fairly good.
What I am going for is a toggle button to hide/unhide rows based on a number 0 or other integer in column A. Hidden if 0, not if anything else. The probably is that it is hiding rows where 0 is in columns other than A as long as there's a 0 in column A below that point. Here's the code:
Private Sub CommandButton1_Click()
Dim objButton As Object
Dim Z As Long
Dim x As Range
Set objButton = ActiveSheet.CommandButton1
Z = Range("A" & Rows.Count).End(xlUp).Row
Set x = Range("A6:A" & Z)
If objButton.Caption = "Hide Rows" Then
With ActiveSheet
Application.ScreenUpdating = False
For Each cell In Range("A6:A" & Z)
cell.EntireRow.Hidden = cell.Value = 0
Next cell
End With
objButton.Caption = "Unhide Rows"
Else
ActiveSheet.Cells.EntireRow.Hidden = False
objButton.Caption = "Hide Rows"
End If
Application.Goto Range("A1"), Scroll:=True
End Sub
Bookmarks