Hide Columns based on checkbox values

G

Guest

I have a 'main' worksheet which features a series of checkboxes next to
criteria in drop down boxes. They are to show\hide columns on a sheet called
"Report"

The top line is an "all" which, when selected, marks all 12 boxes as true.
Underneath on seperate lines are the 12 other checkboxes.

I want to be able to:
1. If "all" is selected, show all columns on "Report" OR
2. Based on the value of each checkbox, show or hide the related column in
"Report"

I assume that I will have to have code similar to:
Private Sub CheckBox2_Click()
Worksheets("Report").Activate
Columns("B:B").Select
Selection.EntireColumn.Hidden = True
End Sub

Or maybe

Private Sub CheckBox2_Click()
IF checkbox2 = True
Worksheets("Report").Activate
Columns("B:B").Select
Selection.EntireColumn.Hidden = True
END IF
End Sub
 
G

Guest

You don't need to activate the sheet and you don't need to select the column.
This code will act as a toggle for hiding/showing column B in Sheet2.


With ThisWorkbook.Sheets("Sheet2").Columns("B")
.Hidden = Not .Hidden
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top