Worksheet Macro to Hide Rows and Columns based on multiple cell values

Studk22

New Member
Joined
May 28, 2010
Messages
16
Hi,

I have two different data validations with dropdown lists on a worksheet. The first list in cell B20 is for a type of chair. The second list in cell H20 is for the backrest type of chair. If I select "Task" in cell B20 and I select "Mesh" in cell "H20" then I want rows 31:32 to be not be hidden and rows 33:34 to be hidden. If I don't select that specific combination then I want rows 31:32 to be hidden and rows 33:34 to not be hidden. The worksheet macro that I have is as follows (but obviously doesn't work):

Private Sub Worksheet_Change(ByVal Target As Range)

If Sheets("X").Range("b20") = "Task" Then
If Sheets("X").Range("h20") = "Mesh" Then
Worksheets("X").Range("31:32").EntireRow.Hidden = False
Worksheets("X").Range("33:34").EntireRow.Hidden = True
Else: Worksheets("X").Range("31:32").EntireRow.Hidden = True
Worksheets("X").Range("33:34").EntireRow.Hidden = False
End If

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Studk22,
try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("X").Range("b20") = "Task" And Sheets("X").Range("h20") = "Mesh" Then
        Worksheets("X").Range("31:32").EntireRow.Hidden = False
        Worksheets("X").Range("33:34").EntireRow.Hidden = True
Else
    Worksheets("X").Range("33:34").EntireRow.Hidden = False
End If
End Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,312
Members
449,499
Latest member
HockeyBoi

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