vendredi 13 octobre 2017

If statement is not working in Excel VBA

Iam trying to create a simple if statement in Excel with VBA.

I'm creating a new checkbox

Adds the following code to the box.

Sub CheckBox1_Click()
   HideRows "2:5"
End Sub

Sub HideRows(rowRange)
If CheckBox1 = False Then
   Rows(rowRange).EntireRow.Hidden = True
   Else: Rows(rowRange).EntireRow.Hidden = False
   End If
End Sub

Result: The rows are hidden both if the checkbox is checked or unchecked.

(checkbox is checked)

All rows are visible

Uncheck the checkbox

Result: All rows are hidden

(checkbox is unchecked)

All rows are visible

Uncheck the checkbox

Result: All rows are hidden




Aucun commentaire:

Enregistrer un commentaire