Reword error message

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
636
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I would like to reword this error message in my own message box. I would like to remove the Run-Time error message number. Thanks.
1739439828695.png
 
Hello,

You need to use the On Error statement (VBA) | Microsoft Learn
In combination with the Err object | Microsoft Learn.

Something like below. Of course you need to adapt the number 11 in the code to the one of your error. That's if you want to target a specific error, you can also check if Err.Number <> 0 which is true for all errors.


VBA Code:
Sub Example()
  Dim myCalc As Long
  ' we expect the error after this line
  On Error Resume Next
  myCalc = 5 / 0 ' raise error
  If Err.Number = 11 Then
    ' Error message
    MsgBox "Error: trying to do a division by 0!", vbCritical
    ' handling the default values to prevent the rest of the code from crashing
    myCalc = 1
    ' resetting the error object
    Err.Clear
  End If
  On Error GoTo 0

  Debug.Print myCalc ' Prints 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,837
Messages
6,193,251
Members
453,784
Latest member
Chandni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top