VBA to show/hide worksheet based on a cell in another worksheet

Sunny London

New Member
Joined
Sep 21, 2010
Messages
29
Can you help me - what is the VBA to show/hide one worksheet based on a cell in another worksheet?

e.g. if a certain cell is populated, can that trigger a macro to automatically show another worksheet or, if the cell is not populated can the macro run automatically to hide the other worksheet? Thanks.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try this: right click the sheet tab, select View Code and paste in

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A1" Then Sheets("Sheet4").Visible = Target.Value <> ""
End Sub

Change the cell reference and sheet name to suit.
 
Upvote 0
Thanks, I need it to be spelt out a bit more though, I'm new to VBA.

I've made my query more specific, in case that helps.

In my 'Data Input' worksheet I've named cell B41 'ForEx1' which contains a drop down menu, if the selction is blank I want worksheets "Foreign Currency 1" and "Foreign Currency 2" to be hidden. But if the user selects one of the options from the drop down list, e.g. 'Euro', 'Yen' or 'GBP', I want worksheets "Foreign Currency 1" and "Foreign Currency 2" to be visible.

Can you advise on what I put where in the VBA code you suggested.

Many thanks.
 
Upvote 0
Right click the Data Input tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B41" Then
    Sheets("Foreign Currency 1").Visible = Target.Value <> ""
    Sheets("Foreign Currency 2").Visible = Target.Value <> ""
End If
End Sub
 
Upvote 0
That worked a treat, but I have one other related query.

I have another cell, B44 and when B44 is blank I want 2 different worksheets "Foreign Sales" and "Foreign Payments" hidden.

I tried replicating the VBA you gave me, but it either needs a new Sub name or I need another loop included in the first macro. I've tried different things but none is working, could you help again please?
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "B41" Then
    Sheets("Foreign Currency 1").Visible = Target.Value <> ""
    Sheets("Foreign Currency 2").Visible = Target.Value <> ""
ElseIf Target.Address(False, False) = "B44" Then
    Sheets("Foreign Sales").Visible = Target.Value <> ""
    Sheets("Foreign Payments").Visible = Target.Value <> ""
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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