stacson2019
New Member
- Joined
- Apr 12, 2019
- Messages
- 1
Hi there,
I'm trying to show and hide rows based on a drop down validation list which contains numbers 1 to 10.
I can display the correct amount of rows when I select a number from the list i.e. select 5 I get 5 rows. If I change my mind and want 8 rows I get 8 rows. What I can't do is if I change my selection to say 3, I can't get it to hide rows 4 and 5. This list controls the same details in two different places on the worksheet.
Pretty new to VBA so struggling to get my head around what is needed to get this working. I understand this is probably a long winded way to get this working... Any help sorting out this code would be very much appreciated.
Cheers
I'm trying to show and hide rows based on a drop down validation list which contains numbers 1 to 10.
I can display the correct amount of rows when I select a number from the list i.e. select 5 I get 5 rows. If I change my mind and want 8 rows I get 8 rows. What I can't do is if I change my selection to say 3, I can't get it to hide rows 4 and 5. This list controls the same details in two different places on the worksheet.
Pretty new to VBA so struggling to get my head around what is needed to get this working. I understand this is probably a long winded way to get this working... Any help sorting out this code would be very much appreciated.
Cheers
Code:
Public Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("SRUAdd").Address Then
If Range("SRUAdd").Value = "0" Then
Rows((Target.Row + 4) & ":" & (Target.Row + 13)).EntireRow.Hidden = True
Rows((Target.Row + 38) & ":" & (Target.Row + 47)).EntireRow.Hidden = True
ElseIf Range("SRUAdd").Value = "1" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 4)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 38)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "2" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 5)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 39)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "3" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 6)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 40)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "4" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 7)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 41)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "5" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 8)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 42)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "6" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 9)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 43)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "7" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 10)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 44)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "8" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 11)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 45)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "9" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 12)).EntireRow.Hidden = False
Rows((Target.Row + 3) & ":" & (Target.Row + 46)).EntireRow.Hidden = False
ElseIf Range("SRUAdd").Value = "10" Then
Rows((Target.Row + 2) & ":" & (Target.Row + 13)).EntireRow.Hidden = False
Rows((Target.Row + 33) & ":" & (Target.Row + 47)).EntireRow.Hidden = False
End If
End If
End Sub