Good Morning All,
I'm trying to write a macro that shows and hides rows on the click of a button.
I have rows 33 - 51 - of which certain groupings need to show when a specific user input is detected.
I was trying to make so that the selection was converted to a number (1/2/3/0) with formulas in the sheet (reference cell P1) and then the macro would show or hide rows depending on that.
I have pasted my current progress below: (Note - I'm brand new at this so it may be completely wrong)
Private Sub CheckBox2_Click()
If (Range("P1").Value) = 1 Then
Rows("33:41").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
End If
If (Range("P1").Value) = 2 Then
Rows("42:51").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
If (Range("P1").Value) = 3 Then
Rows("33:36").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
If (Range("P1").Value) = 0 Then
Rows("33:36").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
Range("A1").Select
End Sub
Currently though doing it this way doesn't seem to work - I have other macros with this setup in my sheet but they are much more simple.
Any assistance would be greatly appreciated.
Thanks in advance!
I'm trying to write a macro that shows and hides rows on the click of a button.
I have rows 33 - 51 - of which certain groupings need to show when a specific user input is detected.
I was trying to make so that the selection was converted to a number (1/2/3/0) with formulas in the sheet (reference cell P1) and then the macro would show or hide rows depending on that.
I have pasted my current progress below: (Note - I'm brand new at this so it may be completely wrong)
Private Sub CheckBox2_Click()
If (Range("P1").Value) = 1 Then
Rows("33:41").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
End If
If (Range("P1").Value) = 2 Then
Rows("42:51").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
If (Range("P1").Value) = 3 Then
Rows("33:36").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
If (Range("P1").Value) = 0 Then
Rows("33:36").Select
End If
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
Range("A1").Select
End Sub
Currently though doing it this way doesn't seem to work - I have other macros with this setup in my sheet but they are much more simple.
Any assistance would be greatly appreciated.
Thanks in advance!