View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] jan120253@gmail.com is offline
external usenet poster
 
Posts: 40
Default My code stops working

I have the follwoing code in Sheet1. Using it, I can hide og show specific sheets by putting x'es in cells A1 to H1. It woeks nicely, but if I rename just one of my sheets, it stops working all together. It doesn't show any errors, absolutely nothing happens. The code is simply not run at all. Even if I put a Stop in the very first line of code, it doesn't get there.

Any ideas

Regards
Jan

PS! I use Danish versions of Excel 2007and 2010.

The code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim tar As String
tar = Target.Address
On Error GoTo err

Select Case tar
Case Is = "$A$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(2).Visible = True
Else
Sheets(2).Visible = False
End If
Case Is = "$B$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(3).Visible = True
Else
Sheets(3).Visible = False
End If
Case Is = "$C$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(4).Visible = True
Else
Sheets(4).Visible = False
End If
Case Is = "$D$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(5).Visible = True
Else
Sheets(5).Visible = False
End If
Case Is = "$E$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(6).Visible = True
Else
Sheets(6).Visible = False
End If
Case Is = "$F$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(7).Visible = True
Else
Sheets(7).Visible = False
End If
Case Is = "$G$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(8).Visible = True
Else
Sheets(8).Visible = False
End If
Case Is = "$H$1"
If UCase(Range(tar).Value) = "X" Then
Sheets(9).Visible = True
Else
Sheets(9).Visible = False
End If
Case Else
Exit Sub
End Select
err:

If err.Number = 9 Then
MsgBox "Du kan ikke vise og skjule et ark, som ikke eksisterer. Prøv med et andet ark!", vbCritical + vbOKOnly
End If

End Sub