please how to make tick box in excel make work with "2 macros"?
I need it, when checked, then hide some rows, and when unchecked, then unhide it. How can I do that?
I have this macro:
Sub bodnariucova_jednotlivci()
Columns("U:EW").Hidden = True
End Sub
EDIT: I edited it like this
Sub bodnariucova_jednotlivci()
Dim cBox As CheckBox
Set cBox = ActiveSheet.CheckBoxes(LName)
If cBox.Value > 0 Then
Columns("U:EZ").Hidden = True
Else
Columns("U:EZ").Hidden = False
End If
End Sub
But when I run it I get Run-time error '1004' Can not get properties CheckBoxes of class Worksheet (something like that, just in my language).
Answer
You need not two macros, you can do this in one. But have to ensure that you use a CheckBox from the ActiveX-Toolbar.
Edit: Insert new CheckBox, right click it and choose "Show code" (or similar in your language). The new Checkbox gets a name like CheckBox1
and the shown macro is named therefore CheckBox1_Click()
.
Private Sub CheckBox1_Click()
If CheckBox1.Value = True then
Columns("U:EW").Hidden = True
Else
Columns("U:EW").Hidden = False
End If
End Sub
And with some boolean logic you can simplify this macro:
Private Sub CheckBox1_Click()
Columns("U:EW").Hidden = CheckBox1.Value
End Sub
No comments:
Post a Comment