I have an issue that makes no sense to me.
Option Explicit
Private Sub Worksheet_Calculate()
Dim Chtob As ChartObject
Dim wks As Worksheet
Set wks = ActiveSheet
On Error GoTo Terminate
For Each Chtob In ActiveSheet.ChartObjects
With Chtob.Chart
If wks.Range("$G$2").Value <> .Axes(xlCategory).MaximumScale Then
.Axes(xlCategory).MaximumScale = wks.Range("$G$2").Value
End If
If wks.Range("$C$2").Value <> .Axes(xlCategory).MinimumScale Then
.Axes(xlCategory).MinimumScale = wks.Range("$C$2").Value
End If
If wks.Range("$G$2").Value <> .Axes(xlCategory, xlSecondary).MaximumScale Then
.Axes(xlCategory, xlSecondary).MaximumScale = wks.Range("$G$2").Value
End If
If wks.Range("$C$2").Value <> .Axes(xlCategory, xlSecondary).MinimumScale Then
.Axes(xlCategory, xlSecondary).MinimumScale = wks.Range("$C$2").Value
End If
End With
Next
Exit Sub
Terminate:
MsgBox "Storm Event Not Valid, Please check if such event number exists"
End
Exit Sub
This macro is used on a tab that has two charts. When a certain cell changes the macro updates the graph scale. This tab will be then duplicated numerous times to show different time events.
The issue arises when someone else tries to open this file. The moment the file is open they get the error to pop up as many times as the amount of tabs created. This for some reason causes a different tab with a different graph to reset it's x scale. This different tab does not have the dynamic macro attached to it and no other macros are being used.
I want to say that a different version of Excel might be part of the problem, but there are times when this doesn't happen.
The way it should work is when somebody enters the wrong value in cell B2 the macro can't execute. So instead of going into debug, one gets an error message. So I need the error portion of the macro to be there.
I should mention that the tab also has another dynamic macro that automatically renames the tab name if the same cell changes.
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
If Not Target.HasFormula Then
If Not Target.Value = vbNullString Then
On Error GoTo ErrHandler
ActiveSheet.Name = "Event" & " " & Target.Value
End If
End If
End If
Exit Sub
ErrHandler:
MsgBox "Error " & Err & ":" & Error(Err)
On Error GoTo 0
End Sub