T
Tom
Hi all,
I have a list in C8:C17 that lists the names of sheets that I would like to
have a macro that UNHIDES the sheets that are listed. Bob Phillips provided
me with this code that works, however, it has a drawback in that after I
enter in the name of the sheet, I have to actually DELETE the contents of
that cell before the macro will run. The sheets that I am UNHIDING have
VLOOKUP formulas on them that reference otheR cells on that main sheet so the
sheet name needs to stay visible for VLOOKUP to have a reference.
Can someone modify this so that the macro will run without having to delete
the cell contents.
Thanks!
Option Explicit
Private Const WS_RANGE As String = "C8:C17" '<=== change to suit
Private prevVal As String
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "" Then
If prevVal <> "" Then
Worksheets(prevVal).Visible = True
End If
Else
Worksheets(.Value).Visible = False
End If
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
prevVal = Target.Value
End If
End Sub
I have a list in C8:C17 that lists the names of sheets that I would like to
have a macro that UNHIDES the sheets that are listed. Bob Phillips provided
me with this code that works, however, it has a drawback in that after I
enter in the name of the sheet, I have to actually DELETE the contents of
that cell before the macro will run. The sheets that I am UNHIDING have
VLOOKUP formulas on them that reference otheR cells on that main sheet so the
sheet name needs to stay visible for VLOOKUP to have a reference.
Can someone modify this so that the macro will run without having to delete
the cell contents.
Thanks!
Option Explicit
Private Const WS_RANGE As String = "C8:C17" '<=== change to suit
Private prevVal As String
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value = "" Then
If prevVal <> "" Then
Worksheets(prevVal).Visible = True
End If
Else
Worksheets(.Value).Visible = False
End If
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
prevVal = Target.Value
End If
End Sub