W
Walter
How would I go about changing the following code to a select case statement?
I got the first snippet of code off of Jon Peltier's website for linking from
a spreadsheet to a chart. Right now I have these eight links which go to 8
different chart tabs. However, I have about 29 more links on my "dashboard"
to go to a bunch more charts that is why I am considering a Select Case
scenario. Thanks for your help!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("D6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("F6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("H6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("J6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("L6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("N6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("P6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("R6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
End Sub
I got the first snippet of code off of Jon Peltier's website for linking from
a spreadsheet to a chart. Right now I have these eight links which go to 8
different chart tabs. However, I have about 29 more links on my "dashboard"
to go to a bunch more charts that is why I am considering a Select Case
scenario. Thanks for your help!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("D6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("F6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("H6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("J6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("L6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("N6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("P6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
If Not Intersect(Target, Range("R6")) Is Nothing Then
On Error Resume Next
Charts(Target.Value).Activate
If Err.Number <> 0 Then
MsgBox "No such chart exists.", vbCritical, "Chart Not Found"
End If
On Error GoTo 0
End If
End Sub