View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Hide sheets based on Cell value

This sub will always exit at the first line, since

IsNull(Intersect(Target, Range("Code")))

will always be false. Try

If Intersect(Target, Range("Code")) Is Nothing Then

instead. Make sure you're putting the code in the worksheet code module.


In article . com,
"vezerid" wrote:

Mike,
I am assuming that the cell that holds the value is named as "Code".
Then you can use this on Change event procedure in your Main sheet
after modifying it as per the comments.

Private Sub Worksheet_Change(ByVal Target As Range)
If IsNull(Intersect(Target, Range("Code"))) Then Exit Sub
Dim OptSheets(1 To 4, 1 To 2) As String
'These are the names of the sheets. First column of the array
OptSheets(1, 1) = "my fist sheet name"
OptSheets(2, 1) = "my second sheet name"
OptSheets(3, 1) = "my third sheet name"
OptSheets(4, 1) = "my fourth sheet name"
'These are the codes corresponding to each sheet. Returned in Main
sheet
OptSheets(1, 2) = "my fist sheet code"
OptSheets(2, 2) = "my second sheet code"
OptSheets(3, 2) = "my third sheet code"
OptSheets(4, 2) = "my fourth sheet code"

For i = 1 To 4
If Range("Code") = OptSheets(i, 2) Then
Sheets(OptSheets(1, 1)).Visible = xlSheetHidden
Else
Sheets(OptSheets(1, 1)).Visible = xlSheetVisible
End If
End Sub

To install: Right-click the sheet tab of Main sheet. Choose View Code.
In the VBA window that appears paste the above code.

HTH
Kostis Vezerides

Mike Milmoe wrote:
I am trying to create a macro that would hide certain sheets based on a drop
down value on the main page. Basically I have main tab, and 4 additional
tabs (Options A, B, C, & D). I have a drop down menu on the main page which
the user chooses which option fits their needs best. Based on that
selection, I want the other tabs to be hidden? Can anyone help?

Thanks!

Mike