jewkes6000
Board Regular
- Joined
- Mar 25, 2020
- Messages
- 60
- Office Version
- 365
- Platform
- Windows
I have the following userform code which loops through columns and hides certain columns based on some criteria; however, if the rows are already hidden, when the toggle button is turned off, it shows the hidden columns which are never supposed to be visible. How do I get the code to loop through visible columns only? Thank you in advance for any help.
VBA Code:
Private Sub LaborButton_Click()
If Controls("LaborButton") = True Then
Dim i As Long
For i = 260 To 15 Step -1
If Cells(3, i) = "Labor" Then Columns(i).Hidden = True
Next i
LaborButton.BackColor = vbRed
Else
For i = 260 To 15 Step -1
If Cells(3, i) = "Labor" Then Columns(i).Hidden = False
Next i
LaborButton.BackColor = vbYellow
End If
ActiveWindow.ScrollColumn = 1
End Sub