I have a worksheet that has several forms on it. Based on a cell selection I want to be able to hide and unhide various rows. I have been able to successfully do this. Now I would like to duplicate the form below the first form and create a separate selected cell to hide/unhide rows for that form. I think I have a syntax issue and am way to green in VBA to figure it out it seems. My code is inserted from right-clicking on the tab and inserting my code. My code works fine based on my C1 selection. I want the to repeat the code for C40.
What am I doing wrong?
What am I doing wrong?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" Then
Dim ITU As String
LR = Cells(Rows.Count, "C").End(xlUp).Row
ITU = Range("C1").Value
Rows.EntireRow.Hidden = False
If ITU = "12" Then
Rows("6:6").EntireRow.Hidden = True
Rows("22:22").EntireRow.Hidden = True
Rows("8:8").EntireRow.Hidden = True
Rows("24:24").EntireRow.Hidden = True
Rows("17:17").EntireRow.Hidden = True
Rows("33:33").EntireRow.Hidden = True
Rows("20:20").EntireRow.Hidden = True
Rows("36:36").EntireRow.Hidden = True
ElseIf ITU = "8" Then
Rows("6:6").EntireRow.Hidden = True
Rows("22:22").EntireRow.Hidden = True
Rows("8:9").EntireRow.Hidden = True
Rows("24:25").EntireRow.Hidden = True
Rows("12:12").EntireRow.Hidden = True
Rows("28:28").EntireRow.Hidden = True
Rows("17:20").EntireRow.Hidden = True
Rows("33:36").EntireRow.Hidden = True
Else
Rows.EntireRow.Hidden = False
End If
End If
If Target.Address = "$C$40" Then
Dim ITU2 As String
LR = Cells(Rows.Count, "C").End(xlUp).Row
ITU2 = Range("C40").Value
Rows.EntireRow.Hidden = False
If ITU2 = "12" Then
Rows("45:45").EntireRow.Hidden = True
Rows("47:47").EntireRow.Hidden = True
Rows("56:56").EntireRow.Hidden = True
Rows("59:59").EntireRow.Hidden = True
Rows("61:61").EntireRow.Hidden = True
Rows("63:63").EntireRow.Hidden = True
Rows("72:72").EntireRow.Hidden = True
Rows("75:75").EntireRow.Hidden = True
ElseIf ITU2 = "8" Then
Rows("45:45").EntireRow.Hidden = True
Rows("47:48").EntireRow.Hidden = True
Rows("51:51").EntireRow.Hidden = True
Rows("55:59").EntireRow.Hidden = True
Rows("61:61").EntireRow.Hidden = True
Rows("63:64").EntireRow.Hidden = True
Rows("67:67").EntireRow.Hidden = True
Rows("71:75").EntireRow.Hidden = True
Else
Rows.EntireRow.Hidden = False
End If
End If
End Sub
Last edited by a moderator: