Use Option button to hide the column
VBA, option Button to hide the column
Excelstarter
3/15/20241 min read
How to Use Option Buttons to hide/unhide the columns


I have 2 groups of option buttons, the first for colors, and the second for pets.
I want to achieve when I select a color and a pet, the respective column will show.
For expamle, if i click on brown and dog, column L will appear and while hiding the rest. If click on brown and cat, column K will appear and hide the rest of them.
So First, Start with Hide All columns
The Logic is to Hide all the column first then unhide the column I need.
I also use IF function to nest another IF function
Sub Hide_All()
Columns("G:Q").EntireColumn.Hidden = True
End Sub
Private Sub Color_Pet()
Hide_All
If Me.OB_Black.Value = True Then
If Me.OB_Cat.Value = True Then Columns("G").EntireColumn.Hidden = False
ElseIf Me.OB_Dog.Value = True Then
Columns("H").EntireColumn.Hidden = False
ElseIf Me.OB_Bird.Value = True Then
Columns("I").EntireColumn.Hidden = False
End If
Checking my Youtube videos for more detail