VBA Hide/Unhide worksheets based on multiple values

RockyAiii

New Member
Joined
Nov 13, 2018
Messages
3
I am completely new to this and everything I've learned so far has been from this forum so thank you. Just one problem which I have found many answers but still can't solve.

I have 2 sheets (Labels, Order Form). The Labels sheet contains the columns Description & Label ID, along with various others that I pull information from. I then have 30 other worksheets that are named as the label ID (DCS-001, DCS-002 etc) and contain the template for that label. What I'm trying to achieve is so that on the Order Form sheet, I can select from the drop down list the description of the label, which then auto populates the label ID and that worksheet would then be visible. I have managed to hide/unhide this for one with the code below, but is there a short code in saying whatever is in cell ?, show the relevant worksheets, not just based on one value. Like a vlookup in VBA?

Private Sub Worksheet_Change(ByVal Target As Range)
If [C17] = "DCS-001" Then
Sheets("DCS-001").Visible = True
Else
Sheets("DCS-001").Visible = False
End If
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
On the Order Form sheet, what cell range has the description drop downs and what cell range has the label IDs?
 
Last edited:
Upvote 0
  • Right-click on the Order Form sheet tab
  • Select View Code from the pop-up context menu
  • Paste the code from below in the worksheet's code module

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_Change([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)
    [color=darkblue]Dim[/color] ws [color=darkblue]As[/color] Worksheet
    [color=darkblue]If[/color] [color=darkblue]Not[/color] Intersect(Range("A17:A50"), Target) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        Application.ScreenUpdating = [color=darkblue]False[/color]
        [color=darkblue]For[/color] [color=darkblue]Each[/color] ws [color=darkblue]In[/color] Worksheets
            [color=darkblue]If[/color] ws.Name [color=darkblue]Like[/color] ("DCS-*") [color=darkblue]Then[/color]
                ws.Visible = IsNumeric(Application.Match(ws.Name, Range("C17:C50"), 0))
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]Next[/color]
        Application.ScreenUpdating = [color=darkblue]True[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Last edited:
Upvote 0
AlphaFrog, this has worked perfectly. Thank you for your time and knowledge in helping resolve my query. Appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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