Hide Rows based on 2 drop-down list

kshitij_dch

Active Member
Joined
Apr 1, 2012
Messages
362
Office Version
  1. 365
  2. 2016
  3. 2007
Platform
  1. Windows
Hello Team ,

I am working on a file where I have 2 Drop Down List in Cell C4 and C5 Respectively

C4 user has 2 options to select ( Win , Loose)
C5 user has 2 options to select ( Make / Wake)

I am struggling to hide rows based on user selection , lets say

If user selects "Win" in C4 and "Make" in C5 than

I want to hide rows ( 4:10 ) and ( 12: 15)

and if user selects "Loose" in C4 and "Make" in C5 than

I want to hide rows (15:17) and (12:15)

Can i do it with VBA??
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Yes it's possible, but we would need to know what rows to hide for every combination.
To be precised

for WIN rows 4 to 10
for Loose rows 15 to 17
for Make rows 12 to 15
for Wake rows 20 to 23
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C4:C5")) Is Nothing Then
      Select Case Target.Address(0, 0)
         Case "C4"
            Rows("4:10").Hidden = Target.Value = "Win"
            Rows("15:17").Hidden = Target.Value = "Loose"
         Case "C5"
            Rows("12:15").Hidden = Target.Value = "Make"
            Rows("20:23").Hidden = Target.Value = "Wake"
      End Select
   End If
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C4:C5")) Is Nothing Then
      Select Case Target.Address(0, 0)
         Case "C4"
            Rows("4:10").Hidden = Target.Value = "Win"
            Rows("15:17").Hidden = Target.Value = "Loose"
         Case "C5"
            Rows("12:15").Hidden = Target.Value = "Make"
            Rows("20:23").Hidden = Target.Value = "Wake"
      End Select
   End If
End Sub
Thank you Fluff , if worked perfectly !!
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C4:C5")) Is Nothing Then
      Select Case Target.Address(0, 0)
         Case "C4"
            Rows("4:10").Hidden = Target.Value = "Win"
            Rows("15:17").Hidden = Target.Value = "Loose"
         Case "C5"
            Rows("12:15").Hidden = Target.Value = "Make"
            Rows("20:23").Hidden = Target.Value = "Wake"
      End Select
   End If
End Sub
When I protect the sheet and perform the action , Error Pops "Unable to set hidden property of the range class", basically protection of sheet is necessary to avoid user changes to the sheet
 
Upvote 0
In that case you need to unprotect the sheet like
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C4:C5")) Is Nothing Then
      Me.Unprotect "abc"
      Select Case Target.Address(0, 0)
         Case "C4"
            Rows("4:10").Hidden = Target.Value = "Win"
            Rows("15:17").Hidden = Target.Value = "Loose"
         Case "C5"
            Rows("12:15").Hidden = Target.Value = "Make"
            Rows("20:23").Hidden = Target.Value = "Wake"
      End Select
   End If
   Me.Protect "abc"
End Sub
Change the abc to whatever your password is.
 
Upvote 0
Solution
In that case you need to unprotect the sheet like
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C4:C5")) Is Nothing Then
      Me.Unprotect "abc"
      Select Case Target.Address(0, 0)
         Case "C4"
            Rows("4:10").Hidden = Target.Value = "Win"
            Rows("15:17").Hidden = Target.Value = "Loose"
         Case "C5"
            Rows("12:15").Hidden = Target.Value = "Make"
            Rows("20:23").Hidden = Target.Value = "Wake"
      End Select
   End If
   Me.Protect "abc"
End Sub
Change the abc to whatever your password is.
Thank you for all your Help!!
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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