Unhide worksheet based on range

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
330
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am hoping someone could help.

I am using the below VBA code to unhide/hide a sheet based on a single cell value of "Yes" or "No". How can I adjust my code to include a range?

Example: If “Yes” is in any cells A1, A2, or A3 (A1:A3) unhide “FINAL” worksheet. If “No” or if a cell is BLANK in any cells within the range then hide worksheet called “FINAL”.

VBA Code:
If [A1] = "Yes" Then
    Sheets("FINAL").Visible = True
Else
    Sheets("FINAL").Visible = False
End If

End Sub

I tired using the code below, but it does not work if A2 or A3 is No. The sheet "FINAL" should still show because A1 is "Yes".

VBA Code:
If [A1] = "Yes" Then
    Sheets("FINAL").Visible = True
Else
    Sheets("FINAL").Visible = False
End If

If [A2] = "Yes" Then
    Sheets("FINAL").Visible = True
Else
    Sheets("FINAL").Visible = False
End If

If [A3] = "Yes" Then
    Sheets("FINAL").Visible = True
Else
    Sheets("FINAL").Visible = False
End If

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You can use Or in VBA so your first line could be

VBA Code:
If ([A1] = "Yes" Or [B1] = "Yes" Or [C1] = "Yes") Then

Remember that will be looking at the active sheet at the time of execution of the line.
 
Upvote 0
Solution
You can use Or in VBA so your first line could be

VBA Code:
If ([A1] = "Yes" Or [B1] = "Yes" Or [C1] = "Yes") Then

Remember that will be looking at the active sheet at the time of execution of the line.

This worked. Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,613
Messages
6,120,515
Members
448,968
Latest member
Ajax40

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