View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default Ignore macro run time error

Phil,

Given the new information, this is how to handle it.

On Error Resume Next ' Ignore lines that throws error (after this statement)
Activechart.Legend.LegendEntries....
' Code to set other legends
On error Goto 0 ' Disable the Error Handling
' Continue with other code

Regards,

Per
"phil" skrev i meddelelsen
...
Per,
Thanks for you answer but this is where the error happens in the code
"ActiveChart.Legend.LegendEntries(5).LegendKey.Sel ect"


There is no legend because there is no data to fetch and it will happen at
each legend entry x5. (I had to write this part of the macro to format the
legend to the preffered layout from default after the pivot refreshed.)

Which part of the code is going in above or below the place where the
error
occurs to stop the error message and allow the macro to complete without
doing the formatting?

"Per Jessen" wrote:

Hi Phil

You need to use the bulit-in error handler.

Below is an example of how it can be done.

Sub Test()
'User enter parameters
On Error GoTo ErrHandler
' Code that throws error
On Error GoTo 0 ' Stop error handler
'Rest of your code
Exit Sub ' Stop before ErrHandler

ErrHandler:
msg = MsgBox("Invalid parameters, macro abort.", vbCritical, "Best
regards,
Per Jessen")
End Sub

Regards,

Per