Please help with VBA code with hide & unhide different rows

Cerber1983

New Member
Joined
Aug 2, 2023
Messages
10
Office Version
  1. 365
Platform
  1. 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)

1695414771890.png


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
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
B18 is dropdown list with products in D3:D9
Ok, probably Application.EnableEvents has been turned off somehow . Try running this code first:
VBA Code:
Sub try()
Application.EnableEvents = True
End Sub
then change B18 value, see what happen.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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