# Code

##### Board Regular
How can I make certain sheets on a workbook visible or very hidden based on answer (yes or no) entered on cells AM20,AM21,AM22 on sheet 2.

Examples:

If AM20=YES, Sheet 15 is visible, If NO Sheet 15 is very hidden.

IF AM21=YES, Sheet 1, 9, and 10 are visible, If NO sheets 1,9, and 10 are Very hidden.

Thank you.

### Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},\$Z\$1:\$Z\$99,\$Y\$1:\$Y\$99),2,False) to lookup Y values to left of Z values.

How about using the following little sub for cell AM20 and Sheet 15 ...

Sub yHideSheets()
'Macro by Yogi Anand on Sep-7-2002
If [AM20] = "Yes" Then Worksheets("Sheet5").Visible = True
Worksheets("Sheet5").Visible = xlVeryHidden
End Sub

Does this help? you can extend this for use with value in cell AM21 and Sheets 1,9, and 10.

Regards!

Yogi

Thanks, but it does not work. Nothing happens.

Any Ideas you all?

Here is what is supposed to happen with the code in my post. You have to have a workbook with at least 5 worksheets. Cell AM20 in Sheet1 is to house "Yes" (without quotes).
Then the following code:

Sub yHideSheets()
'Macro by Yogi Anand on Sep-7-2002
If [A20] = "Yes" Then Worksheets("Sheet5").Visible = True
Worksheets("Sheet5").Visible = xlVeryHidden
End Sub

is to be put in a module (say Module1) of This Workbook.

Then after the code has been put in the right place, and the cell AM20 in Sheet1 houses "Yes" (without quotes"), then on running the code in the sub, the Sheet5 is supposed to become VeryHidden.

I Have tested the code and this indeed does happen.

You may have to check your work step by step to make sure that everything is done correctly.

Regards!

Yogi

Thank you Yogi. The problem is that cell AM20 is on sheet 2. How do I go about changing it to work?

If cell AM20 to be tested is in Sheet2, then change the code to:

Sub yHideSheets()
'Macro by Yogi Anand on Sep-7-2002
If [Sheet2!AM20] = "Yes" Then Worksheets("Sheet5").Visible = True
Worksheets("Sheet5").Visible = xlVeryHidden
End Sub

(By the way, in the earlier code, I had mistyped the cell AM20 as A20)

I hope this helps.

Regards!

Yogi

Replies
15
Views
398
Replies
1
Views
121
Replies
1
Views
328
Replies
4
Views
191
Replies
3
Views
179

1,216,099
Messages
6,128,822
Members
449,470
Latest member
Subhash Chand

### 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.

### Which adblocker are you using?

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

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