how do I produce an error dialogue box in VBA

caltrin

New Member
Joined
Feb 5, 2004
Messages
29
e.g.

when the value of cell D10 becomes higher than 100 %

Excel should display a error message box saying something like


Correction Total Too High ! Please Check
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

jimboy

Well-known Member
Joined
Apr 11, 2002
Messages
2,314
Right mouse over the sheet name (i.e. Sheet1) and select view code, then paste this in, it will run when a change in the sheet is made;

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("D10").Value > 1 Then
If MsgBox("Correction Total Too High ! Please Check", vbOKOnly, "See range D10") = vbOK Then:
End If
End Sub
 
Upvote 0

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
66,558
Office Version
  1. 365
Platform
  1. Windows
Or just use Validation, found under the Data drop down box. This allows you to specify the conditions of the values entered into the specific cells, and allows you to return an error message for incorrect values.

Edit: Validation will only work if a hard coded value is being typed into the cell. If it is a formula, link, or is pasted into the cell, use the code jimboy provided.
 
Upvote 0

Forum statistics

Threads
1,187,179
Messages
5,962,057
Members
438,578
Latest member
MrJimC

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
Top