You werent actually checking the value of the checkboxes, the following line:
CheckboxX = "CheckBox" & x
simply created a variable and populated it with "Checkbox1", "Checkbox2" etc which never equals True.
You need to cycle through the controls in the form and action accordingly.
Private Sub CommandButton1_Click()
Dim cCont As Control
For Each cCont In Me.Controls 'cycle through all elements on the form allocating each in turn to the object "cCont"
If (Left(cCont.Name, 5) = "Check") Then 'check if name of object begins with "Check", if so its a checkbox
y = Int(Right(cCont.Name, Len(cCont.Name) - 8)) + 6 'strip off the word "Checkbox" to leave the number
If (cCont.Value = True) Then ' check if its value is True
Columns(y).EntireColumn.Hidden = False
Else
Columns(y).EntireColumn.Hidden = True
End If
End If
Next cCont
Unload UserForm1
End Sub
Bookmarks