Hi,
I'm trying to create a simple toggle to hide or unhide sheets using VBA but I can't get the code below to work. It gives a 'With or object variable not set' error as the wksheet variable is set to nothing.
Can anyone give me a pointer?
Thanks,
Roy
Sub ToggleIDS()
Dim wksheet As Worksheet
With wksheet
If .Name = "Incorrectly Requested" Then
If .Visible Then
.Visible = xlSheetVeryHidden
ElseIf Not .Visible Then
.Visible = xlSheetVisible
End If
End If
End With
End Sub
I'm trying to create a simple toggle to hide or unhide sheets using VBA but I can't get the code below to work. It gives a 'With or object variable not set' error as the wksheet variable is set to nothing.
Can anyone give me a pointer?
Thanks,
Roy
Sub ToggleIDS()
Dim wksheet As Worksheet
With wksheet
If .Name = "Incorrectly Requested" Then
If .Visible Then
.Visible = xlSheetVeryHidden
ElseIf Not .Visible Then
.Visible = xlSheetVisible
End If
End If
End With
End Sub