cwb1021
04-25-2017, 06:16 AM
Good morning experts,
I'm trying to write a procedure that can loop through all selected checkboxes in a userform and if selected, hide rows in the worksheet. So I've started by trying to get just one checkbox to hide rows with the below code. This does not give me any errors, but does not do anything either.
So for example, I
There are 3 checkboxes in the userform: checkbox 1 is labeled "1", checkbox 2 is labeled "1.5", and checkbox 3 is labeled "2"
If checkbox 1 and checkbox 2 are selected, I would like for all rows in the worksheet whose value in column AM is not equal to "1" or "1.5" to be hidden. And, if no checkboxes are selected, no rows would be hidden.
Private Sub FilterButton1_Click()
Dim Checked As Control
Dim LengthRange As Range, LengthCell As Range
Dim x As Long, y As Long, z As Long
Set LengthRange = Sheets("Sheet1").Range(("AM2"), Range("AM2").End(xlDown))
x = 1
y = 1.5
z = 2
For Each Checked In UserForm1.Controls
If TypeName(Checked) = "Checkbox" Then
If Checked.Value = True Then
For Each LengthCell In LengthRange
If LengthCell.Value <> x Then
LengthCell.EntireRow.Hide
End If
Next LengthCell
End If
End If
Next Checked
End Sub
Any suggestions on how to do this?
Thanks!
Chris
I'm trying to write a procedure that can loop through all selected checkboxes in a userform and if selected, hide rows in the worksheet. So I've started by trying to get just one checkbox to hide rows with the below code. This does not give me any errors, but does not do anything either.
So for example, I
There are 3 checkboxes in the userform: checkbox 1 is labeled "1", checkbox 2 is labeled "1.5", and checkbox 3 is labeled "2"
If checkbox 1 and checkbox 2 are selected, I would like for all rows in the worksheet whose value in column AM is not equal to "1" or "1.5" to be hidden. And, if no checkboxes are selected, no rows would be hidden.
Private Sub FilterButton1_Click()
Dim Checked As Control
Dim LengthRange As Range, LengthCell As Range
Dim x As Long, y As Long, z As Long
Set LengthRange = Sheets("Sheet1").Range(("AM2"), Range("AM2").End(xlDown))
x = 1
y = 1.5
z = 2
For Each Checked In UserForm1.Controls
If TypeName(Checked) = "Checkbox" Then
If Checked.Value = True Then
For Each LengthCell In LengthRange
If LengthCell.Value <> x Then
LengthCell.EntireRow.Hide
End If
Next LengthCell
End If
End If
Next Checked
End Sub
Any suggestions on how to do this?
Thanks!
Chris