Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,066
- Office Version
- 2016
- Platform
- Windows
I have 30 columns that the user could hide if they wished. Different users will need to look at different columns so the option to hide and unhide columns is needed.
I have written this code below to hide and unhide a column when a check box is checked on a user form. Ideally I would like it to work from a command button.
Is there a better way I could write this code to hide certain columns. Lets say columns A,C,D,F,G,I,M,P
Or will I have to write this for each column and checkbox
Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
Sheet1.Columns("A").EntireColumn.Hidden = True
Else
If CheckBox1.Value = True Then
Sheet1.Columns("A").EntireColumn.Hidden = False
End If
End If
End Sub
I have written this code below to hide and unhide a column when a check box is checked on a user form. Ideally I would like it to work from a command button.
Is there a better way I could write this code to hide certain columns. Lets say columns A,C,D,F,G,I,M,P
Or will I have to write this for each column and checkbox
Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
Sheet1.Columns("A").EntireColumn.Hidden = True
Else
If CheckBox1.Value = True Then
Sheet1.Columns("A").EntireColumn.Hidden = False
End If
End If
End Sub