Hide/Show Rows based on a List with numeric values

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

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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top