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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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
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,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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