Forum Discussion
MrPet88
Apr 25, 2024Copper Contributor
Activate/deactivate checkboxes using a macro, when those checkboxes have also macros assigned
I have several checkboxes in my table, and each check box as a macro assigned to hide or unhide a column, depending on if it is checked or not. For example: Sub HideUnhideC()
Range("C:C").En...
- Apr 25, 2024
Use ActiveX check boxes instead of Form Control check boxes.
All code then goes into the worksheet module:
Private Sub CheckBox1_Click() Range("C:C").EntireColumn.Hidden = Not Me.CheckBox1 End Sub Private Sub CheckBox2_Click() Range("D:D").EntireColumn.Hidden = Not Me.CheckBox2 End Sub Private Sub CommandButton1_Click() Dim ctl As OLEObject For Each ctl In Me.OLEObjects If TypeName(ctl.Object) = "CheckBox" Then ctl.Object.Value = True End If Next ctl End Sub Private Sub CommandButton2_Click() Dim ctl As OLEObject For Each ctl In Me.OLEObjects If TypeName(ctl.Object) = "CheckBox" Then ctl.Object.Value = False End If Next ctl End Sub
HansVogelaar
MVP
Use ActiveX check boxes instead of Form Control check boxes.
All code then goes into the worksheet module:
Private Sub CheckBox1_Click()
Range("C:C").EntireColumn.Hidden = Not Me.CheckBox1
End Sub
Private Sub CheckBox2_Click()
Range("D:D").EntireColumn.Hidden = Not Me.CheckBox2
End Sub
Private Sub CommandButton1_Click()
Dim ctl As OLEObject
For Each ctl In Me.OLEObjects
If TypeName(ctl.Object) = "CheckBox" Then
ctl.Object.Value = True
End If
Next ctl
End Sub
Private Sub CommandButton2_Click()
Dim ctl As OLEObject
For Each ctl In Me.OLEObjects
If TypeName(ctl.Object) = "CheckBox" Then
ctl.Object.Value = False
End If
Next ctl
End Sub
MrPet88
Apr 29, 2024Copper Contributor