Hide/Unhide Rows in other sheets based on selection from 3way drop down list

%3CLINGO-SUB%20id%3D%22lingo-sub-1615484%22%20slang%3D%22en-US%22%3EHide%2FUnhide%20Rows%20in%20other%20sheets%20based%20on%20selection%20from%203way%20drop%20down%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1615484%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20working%20on%20a%20document%20where%20based%20on%20the%20selection%20in%20a%20cell%26nbsp%3B(%22%24F%246%22)%20of%20%3CSTRONG%3E%3CEM%3ENo%2C%20EWP%20%3C%2FEM%3E%3C%2FSTRONG%3Eor%3CSTRONG%3E%3CEM%3E%20AusPost%26nbsp%3B%3C%2FEM%3E%3C%2FSTRONG%3Edifferent%20rows%20in%20corresponding%20worksheets%20hide%2Funhide.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20issue%20I%20am%20having%20is%3A%3C%2FP%3E%3CP%3Eif%20I%20select%20%22%3CSTRONG%3ENo%3C%2FSTRONG%3E%22%20in%26nbsp%3B(%22%24F%246%22)%20it%20hides%20everything%20I%20require%20hidden%20(no%20issue)%3C%2FP%3E%3CP%3Eif%20I%20select%20either%20%22%3CSTRONG%3EEWP%3C%2FSTRONG%3E%22%20or%20%22%3CSTRONG%3EAusPost%3C%2FSTRONG%3E%22%20it%20unhides%20the%20correct%20rows%20(no%20issue)%3C%2FP%3E%3CP%3Eif%20I%20select%26nbsp%3Beither%20%22%3CSTRONG%3EEWP%3C%2FSTRONG%3E%22%20or%20%22%3CSTRONG%3EAusPost%22%26nbsp%3B%3C%2FSTRONG%3Eafter%20having%20already%20selected%20the%20opposite%20value%26nbsp%3B%22%3CSTRONG%3EEWP%3C%2FSTRONG%3E%22%20or%20%22%3CSTRONG%3EAusPost%22%26nbsp%3B%3C%2FSTRONG%3Eit%20will%20unhide%20the%20correct%20rows%20but%20not%20rehide%20the%20others.%3CBR%20%2F%3E%3CBR%20%2F%3Esee%20code%20and%20screenshot%20of%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EIf%20Not%20Application.Intersect(Range(%22%24F%246%22)%2C%20Range(Target.Address))%20Is%20Nothing%20Then%3CBR%20%2F%3ESelect%20Case%20Target.Value%3C%2FP%3E%3CP%3ECase%20Is%20%3D%20%22No%22%3A%20Worksheets(%22Contractors%22).Range(%2215%3A16%2C39%3A44%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22EWP%22%3A%20Worksheets(%22Contractors%22).Range(%2215%3A15%2C39%3A41%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3ECase%20Is%20%3D%20%22EWP%22%3A%20Worksheets(%22Contractors%22).Range(%2216%3A16%2C42%3A44%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22AusPost%22%3A%20Worksheets(%22Contractors%22).Range(%2215%3A15%2C39%3A41%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22AusPost%22%3A%20Worksheets(%22Contractors%22).Range(%2216%3A16%2C42%3A44%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3EEnd%20Select%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EIf%20Not%20Application.Intersect(Range(%22%24F%246%22)%2C%20Range(Target.Address))%20Is%20Nothing%20Then%3CBR%20%2F%3ESelect%20Case%20Target.Value%3C%2FP%3E%3CP%3ECase%20Is%20%3D%20%22No%22%3A%20Worksheets(%22Consultants%22).Range(%2218%3A21%3A22%3A24%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22EWP%22%3A%20Worksheets(%22Consultants%22).Range(%2218%3A21%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3ECase%20Is%20%3D%20%22EWP%22%3A%20Worksheets(%22Consultants%22).Range(%2222%3A24%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22AusPost%22%3A%20Worksheets(%22Consultants%22).Range(%2222%3A24%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3ECase%20Is%20%3D%20%22AusPost%22%3A%20Worksheets(%22Consultants%22).Range(%2218%3A21%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3EEnd%20Select%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E'%20Contractors%20Worksheet%20-%2042%3A44%20%3D%20AusPost%20specific%20Lines%3CBR%20%2F%3E'%20Consultants%20Worksheet%20-%2022%3A24%20%3D%20AusPost%20specific%20Lines%3CBR%20%2F%3E'%20Contractors%20Worksheet%20-%2015%2C39%3A41%20%3D%20EWP%20specific%20Lines%3CBR%20%2F%3E'%20Consultants%20Worksheet%20-%2018%3A21%20%3D%20EWP%20specific%20Lines%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jacksonattwood_0-1598513656760.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F214935iAABE3311B7EC2EEB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22jacksonattwood_0-1598513656760.png%22%20alt%3D%22jacksonattwood_0-1598513656760.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1615484%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1615532%22%20slang%3D%22en-US%22%3ERe%3A%20Hide%2FUnhide%20Rows%20in%20other%20sheets%20based%20on%20selection%20from%203way%20drop%20down%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1615532%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20was%20the%20original%20code%20in%20the%20document%20when%20it%20was%20a%20%22%3CSTRONG%3Eyes%3C%2FSTRONG%3E%22%2C%26nbsp%3B%20%22%3CSTRONG%3Eno%3C%2FSTRONG%3E%22%20or%26nbsp%3B%20%22%3CSTRONG%3Eblank%3C%2FSTRONG%3E%22%26nbsp%3B%20dropdown%20list%20and%20it%26nbsp%3B%20would%20correctly%20unhide%2Fhide%20the%20rows.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EIf%20Not%20Application.Intersect(Range(%22%24F%246%22)%2C%20Range(Target.Address))%20Is%20Nothing%20Then%3CBR%20%2F%3ESelect%20Case%20Target.Value%3C%2FP%3E%3CP%3ECase%20Is%20%3D%20%22No%22%3A%20Worksheets(%22Contractors%22).Range(%2215%3A15%2C39%3A41%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22Yes%22%3A%20Worksheets(%22Contractors%22).Range(%2215%3A15%2C39%3A41%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3EEnd%20Select%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EIf%20Not%20Application.Intersect(Range(%22%24F%246%22)%2C%20Range(Target.Address))%20Is%20Nothing%20Then%3CBR%20%2F%3ESelect%20Case%20Target.Value%3C%2FP%3E%3CP%3ECase%20Is%20%3D%20%22No%22%3A%20Worksheets(%22Consultants%22).Range(%2218%3A21%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3ECase%20Is%20%3D%20%22Yes%22%3A%20Worksheets(%22Consultants%22).Range(%2218%3A21%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3EEnd%20Select%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1615916%22%20slang%3D%22en-US%22%3ERe%3A%20Hide%2FUnhide%20Rows%20in%20other%20sheets%20based%20on%20selection%20from%203way%20drop%20down%20list%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1615916%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F772907%22%20target%3D%22_blank%22%3E%40jacksonattwood%3C%2FA%3E%26nbsp%3BCombine%20all%20the%20hide%20and%20unhide%20actions%20into%20one%20Case%20statement%2C%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0A%0AIf%20Not%20Application.Intersect(Range(%22%24F%246%22)%2C%20Range(Target.Address))%20Is%20Nothing%20Then%0ASelect%20Case%20Target.Value%0ACase%20Is%20%3D%20%22No%22%3A%0AWorksheets(%22Contractors%22).Range(%2215%3A16%2C39%3A44%22).EntireRow.Hidden%20%3D%20True%0AWorksheets(%22Consultants%22).Range(%2218%3A24%22).EntireRow.Hidden%20%3D%20True%0A%0ACase%20Is%20%3D%20%22EWP%22%3A%0AWorksheets(%22Contractors%22).Range(%2215%3A15%2C39%3A41%22).EntireRow.Hidden%20%3D%20False%0AWorksheets(%22Contractors%22).Range(%2216%3A16%2C42%3A44%22).EntireRow.Hidden%20%3D%20True%0AWorksheets(%22Consultants%22).Range(%2218%3A21%22).EntireRow.Hidden%20%3D%20False%0AWorksheets(%22Consultants%22).Range(%2222%3A24%22).EntireRow.Hidden%20%3D%20True%0A%0ACase%20Is%20%3D%20%22AusPost%22%3A%0AWorksheets(%22Contractors%22).Range(%2215%3A15%2C39%3A41%22).EntireRow.Hidden%20%3D%20True%0AWorksheets(%22Contractors%22).Range(%2216%3A16%2C42%3A44%22).EntireRow.Hidden%20%3D%20False%0AWorksheets(%22Consultants%22).Range(%2222%3A24%22).EntireRow.Hidden%20%3D%20False%0AWorksheets(%22Consultants%22).Range(%2218%3A21%22).EntireRow.Hidden%20%3D%20True%0A%0AEnd%20Select%0AEnd%20If%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETested%20it%20and%20it%20seems%20to%20work%20as%20intended.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi,

 

I am working on a document where based on the selection in a cell ("$F$6") of No, EWP or AusPost different rows in corresponding worksheets hide/unhide. 

The issue I am having is:

if I select "No" in ("$F$6") it hides everything I require hidden (no issue)

if I select either "EWP" or "AusPost" it unhides the correct rows (no issue)

if I select either "EWP" or "AusPost" after having already selected the opposite value "EWP" or "AusPost" it will unhide the correct rows but not rehide the others.

see code and screenshot of code.

 

Thanks

 

Private Sub Worksheet_Change(ByVal Target As Range)


If Not Application.Intersect(Range("$F$6"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value

Case Is = "No": Worksheets("Contractors").Range("15:16,39:44").EntireRow.Hidden = True
Case Is = "EWP": Worksheets("Contractors").Range("15:15,39:41").EntireRow.Hidden = False
Case Is = "EWP": Worksheets("Contractors").Range("16:16,42:44").EntireRow.Hidden = True
Case Is = "AusPost": Worksheets("Contractors").Range("15:15,39:41").EntireRow.Hidden = True
Case Is = "AusPost": Worksheets("Contractors").Range("16:16,42:44").EntireRow.Hidden = False
End Select
End If
If Not Application.Intersect(Range("$F$6"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value

Case Is = "No": Worksheets("Consultants").Range("18:21:22:24").EntireRow.Hidden = True
Case Is = "EWP": Worksheets("Consultants").Range("18:21").EntireRow.Hidden = False
Case Is = "EWP": Worksheets("Consultants").Range("22:24").EntireRow.Hidden = True
Case Is = "AusPost": Worksheets("Consultants").Range("22:24").EntireRow.Hidden = False
Case Is = "AusPost": Worksheets("Consultants").Range("18:21").EntireRow.Hidden = True
End Select
End If

End Sub

' Contractors Worksheet - 42:44 = AusPost specific Lines
' Consultants Worksheet - 22:24 = AusPost specific Lines
' Contractors Worksheet - 15,39:41 = EWP specific Lines
' Consultants Worksheet - 18:21 = EWP specific Lines

 

 

jacksonattwood_0-1598513656760.png

 

2 Replies
Highlighted

This was the original code in the document when it was a "yes",  "no" or  "blank"  dropdown list and it  would correctly unhide/hide the rows.

Private Sub Worksheet_Change(ByVal Target As Range)


If Not Application.Intersect(Range("$F$6"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value

Case Is = "No": Worksheets("Contractors").Range("15:15,39:41").EntireRow.Hidden = True
Case Is = "Yes": Worksheets("Contractors").Range("15:15,39:41").EntireRow.Hidden = False
End Select
End If
If Not Application.Intersect(Range("$F$6"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value

Case Is = "No": Worksheets("Consultants").Range("18:21").EntireRow.Hidden = True
Case Is = "Yes": Worksheets("Consultants").Range("18:21").EntireRow.Hidden = False
End Select
End If

End Sub

Highlighted

@jacksonattwood Combine all the hide and unhide actions into one Case statement, like this:

 

 

 

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Application.Intersect(Range("$F$6"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "No":
Worksheets("Contractors").Range("15:16,39:44").EntireRow.Hidden = True
Worksheets("Consultants").Range("18:24").EntireRow.Hidden = True

Case Is = "EWP":
Worksheets("Contractors").Range("15:15,39:41").EntireRow.Hidden = False
Worksheets("Contractors").Range("16:16,42:44").EntireRow.Hidden = True
Worksheets("Consultants").Range("18:21").EntireRow.Hidden = False
Worksheets("Consultants").Range("22:24").EntireRow.Hidden = True

Case Is = "AusPost":
Worksheets("Contractors").Range("15:15,39:41").EntireRow.Hidden = True
Worksheets("Contractors").Range("16:16,42:44").EntireRow.Hidden = False
Worksheets("Consultants").Range("22:24").EntireRow.Hidden = False
Worksheets("Consultants").Range("18:21").EntireRow.Hidden = True

End Select
End If

End Sub

 

 

 

Tested it and it seems to work as intended.