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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,886
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,102
Messages
5,768,102
Members
425,454
Latest member
khoro

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