Cerber1983
New Member
- Joined
- Aug 2, 2023
- Messages
- 10
- Office Version
- 365
- Platform
- Windows
I have a workbook with 2 tabs where:
Tab 1 (General Inputs): Is input tab with List dropdown for one of the fields
Tab 2: Is output tab that is formatted as document
Tab 1 have a cell with drop-down options to choose from:
Apples
Oranges
Tomatoes
Apples & Oranges
Apples & Tomatoes
Oranges & Tomatoes
Apples, Oranges, & Tomatoes
Tab 2 is a document with formatted data pages as a document for each output in Tab 1 (General Inputs):
Rows 404:454 for Apples
Rows 455:505 for Oranges
Rows 506:556 for Tomatoes
Rows 557:607 for Apples & Oranges
Rows 608:658 for Apples & Tomatoes
Rows 659:709 for Oranges & Tomatoes
Rows 353:403 for Apples, Oranges, & Tomatoes
I am trying to write VBA code that will be displaying only pages on Tab 2 based on drop-down value in a cell on Tab 1 (General Inputs)
Below is a code but it doesn't seems to be working
FYI: "Document" Tab is Tab 2 where I need to hide rows based on selection & D162 is a cell on same Tab 2 that is with formula = value of drop-down cell from Tab 1 (General Inputs)
Please help!
Private Sub Worksheet_Change(ByVal Target As Range)
With Sheets("Document")
If Target.Address = "$D$162" Then
If Target.Value = "Apple" Then Rows("353:403").EntireRow.Hidden = True
If Target.Value = "Apple" Then Rows("455:709").EntireRow.Hidden = True
If Target.Value = "Apple" Then Rows("404:454").EntireRow.Hidden = False
If Target.Value = "Orange" Then Rows("353:454").EntireRow.Hidden = True
If Target.Value = "Orange" Then Rows("506:709").EntireRow.Hidden = True
If Target.Value = "Orange" Then Rows("455:505").EntireRow.Hidden = False
If Target.Value = "Tomato" Then Rows("353:505").EntireRow.Hidden = True
If Target.Value = "Tomato" Then Rows("557:709").EntireRow.Hidden = True
If Target.Value = "Tomato" Then Rows("506:556").EntireRow.Hidden = False
If Target.Value = "Apple & Orange" Then Rows("353:556").EntireRow.Hidden = True
If Target.Value = "Apple & Orange" Then Rows("608:709").EntireRow.Hidden = True
If Target.Value = "Apple & Orange" Then Rows("557:607").EntireRow.Hidden = False
If Target.Value = "Apple & Tomato" Then Rows("353:607").EntireRow.Hidden = True
If Target.Value = "Apple & Tomato" Then Rows("659:709").EntireRow.Hidden = True
If Target.Value = "Apple & Tomato" Then Rows("608:658").EntireRow.Hidden = False
If Target.Value = "Orange & Tomato" Then Rows("353:658").EntireRow.Hidden = True
If Target.Value = "Orange & Tomato" Then Rows("659:709").EntireRow.Hidden = False
If Target.Value = "Apple, Orange, & Tomato" Then Rows("404:709").EntireRow.Hidden = True
If Target.Value = "Gold, Platinum, & Diamond" Then Rows("353:403").EntireRow.Hidden = False
End If
End With
End Sub
Tab 1 (General Inputs): Is input tab with List dropdown for one of the fields
Tab 2: Is output tab that is formatted as document
Tab 1 have a cell with drop-down options to choose from:
Apples
Oranges
Tomatoes
Apples & Oranges
Apples & Tomatoes
Oranges & Tomatoes
Apples, Oranges, & Tomatoes
Tab 2 is a document with formatted data pages as a document for each output in Tab 1 (General Inputs):
Rows 404:454 for Apples
Rows 455:505 for Oranges
Rows 506:556 for Tomatoes
Rows 557:607 for Apples & Oranges
Rows 608:658 for Apples & Tomatoes
Rows 659:709 for Oranges & Tomatoes
Rows 353:403 for Apples, Oranges, & Tomatoes
I am trying to write VBA code that will be displaying only pages on Tab 2 based on drop-down value in a cell on Tab 1 (General Inputs)
Below is a code but it doesn't seems to be working
FYI: "Document" Tab is Tab 2 where I need to hide rows based on selection & D162 is a cell on same Tab 2 that is with formula = value of drop-down cell from Tab 1 (General Inputs)
Please help!
Private Sub Worksheet_Change(ByVal Target As Range)
With Sheets("Document")
If Target.Address = "$D$162" Then
If Target.Value = "Apple" Then Rows("353:403").EntireRow.Hidden = True
If Target.Value = "Apple" Then Rows("455:709").EntireRow.Hidden = True
If Target.Value = "Apple" Then Rows("404:454").EntireRow.Hidden = False
If Target.Value = "Orange" Then Rows("353:454").EntireRow.Hidden = True
If Target.Value = "Orange" Then Rows("506:709").EntireRow.Hidden = True
If Target.Value = "Orange" Then Rows("455:505").EntireRow.Hidden = False
If Target.Value = "Tomato" Then Rows("353:505").EntireRow.Hidden = True
If Target.Value = "Tomato" Then Rows("557:709").EntireRow.Hidden = True
If Target.Value = "Tomato" Then Rows("506:556").EntireRow.Hidden = False
If Target.Value = "Apple & Orange" Then Rows("353:556").EntireRow.Hidden = True
If Target.Value = "Apple & Orange" Then Rows("608:709").EntireRow.Hidden = True
If Target.Value = "Apple & Orange" Then Rows("557:607").EntireRow.Hidden = False
If Target.Value = "Apple & Tomato" Then Rows("353:607").EntireRow.Hidden = True
If Target.Value = "Apple & Tomato" Then Rows("659:709").EntireRow.Hidden = True
If Target.Value = "Apple & Tomato" Then Rows("608:658").EntireRow.Hidden = False
If Target.Value = "Orange & Tomato" Then Rows("353:658").EntireRow.Hidden = True
If Target.Value = "Orange & Tomato" Then Rows("659:709").EntireRow.Hidden = False
If Target.Value = "Apple, Orange, & Tomato" Then Rows("404:709").EntireRow.Hidden = True
If Target.Value = "Gold, Platinum, & Diamond" Then Rows("353:403").EntireRow.Hidden = False
End If
End With
End Sub