Pop up error message based on if statement

DMT

New Member
Joined
Jan 21, 2004
Messages
28
Hi,

I want to have an error message box pop up if a cell equals FALSE based on a formula. How do I do this?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How about...

If myCell = False Then
msgbox ("Error")
Else
'carry on
end if
 
Upvote 0
Cell(2,2) is where your If condition is. Lock this cell for editing.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Cells(2, 2) = False Then MsgBox "PLease change the values", vbCritical
End Sub

Hope this helps.
 
Upvote 0
I am having trouble implementing this code. Do I just set up a new macro, paste in your code and edit where the cell reference is? My if statement is in cell AA50. I tried doing this, but nothing happened when cell AA50 equalled zero. What am I doing wrong? Thanks.
 
Upvote 0
No, you do not set up a new macro, you paste this line
Code:
If Cells(50, "AA").Value = 0 Then MsgBox "PLease change the values", vbCritical
in the Worksheet_Change module, which you can find by following these steps.
1. Press Alt + F11 to bring the VBE window.
2. On the left hand side you should see all your sheets you are working on under "Microsoft Excel Objects"
3. Double click the sheet where your formula is.
4. You should see two drop-down boxes one will say "General" and the other "Declarations"
5. Change the "General" to worksheet and "Declarations" to "Change"

Now, try and change your values. Hope this one works and sorry for such a late reply.
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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