I have previously used error handling in VBA successfully, but when trying to use several error handling blocks I can't figure out how to do it.
The code I've written looks like this:
...
On Error GoTo ErrorHandler1
shpArrow1.Left = shpLine.Left + shpLine.Width * Min(Sqr(Calculations.Range("cVolProduct").value / Calculations.Range("cVolRefIndices").value), 2) / 2 - shpArrow1.Width / 2
shpTag1.Left = shpLine.Left + shpLine.Width * Min(Sqr(Calculations.Range("cVolProduct").value / Calculations.Range("cVolRefIndices").value), 2) / 2 - shpTag1.Width / 2
shpArrow2.Left = shpLine.Left + shpLine.Width * Min(Sqr(Calculations.Range("cVolUnderlyings").value / Calculations.Range("cVolRefIndices").value), 2) / 2 - shpArrow2.Width / 2
shpTag2.Left = shpLine.Left + shpLine.Width * Min(Sqr(Calculations.Range("cVolUnderlyings").value / Calculations.Range("cVolRefIndices").value), 2) / 2 - shpTag2.Width / 2
shpIndexLine.Left = shpLine.Left + shpLine.Width / 2 - shpIndexLine.Width / 2
GoTo NoError1
ErrorHandler1:
shpArrow1.Left = shpLine.Left - shpArrow1.Width / 2
shpTag1.Left = shpLine.Left - shpTag1.Width / 2
shpArrow2.Left = shpLine.Left - shpArrow2.Width / 2
shpTag2.Left = shpLine.Left - shpTag2.Width / 2
shpIndexLine.Left = shpLine.Left + shpLine.Width / 2 - shpIndexLine.Width / 2
errorRelativeRisk = 1
NoError1:
On Error GoTo 0
On Error GoTo ErrorHandler2
Output.ChartObjects("ChartHistoryUnderlyings").Activate
ActiveChart.Axes(xlValue).CrossesAt = ActiveChart.Axes(xlValue).MinimumScale
ActiveChart.Axes(xlCategory).CrossesAt = ActiveChart.Axes(xlCategory).MinimumScale
GoTo NoError2
ErrorHandler2:
errorHistUnderl = 1
NoError2:
On Error GoTo 0
...
The second error handling block does not work. I'm guessing that I don't quit the first error handling block correctly. Have tried to find an answer that works for me but without success.
Greatful for any help!
...stand forPrivate Sub DoSomething()andEnd Subrespectively, or there's more to it? I think your code could be easier to follow if you extracted a method out of each "block", each with its own error handling; basically you need to untangle thisGoTo Mess....stands for start and end of sub, but there's some more simple calculations which should not affect the error handling. Basically both of the error handling blocks works if I only use one of them, but to use both maybe I have to "hide" the code by making two short subs instead.