If, then, message, exit sub

sb003848

Board Regular
Joined
Sep 17, 2009
Messages
66
Hello,

I'm trying to figure out how to tell a macro that if cell A1 is empty, to show a message box saying "Cell A1 is empty and needs to be filled out" and then stop the macro.

I already have the following to stop the macro if the cell is empty but what do I need to add for the message box?
If Range("A1") = "" Then Exit Sub

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Code:
If len(Range("A1").Value) = 0 Then
  msgbox "Cell A1 is empty and needs to be filled out"
 Exit Sub
End If
 
Upvote 0
Thanks for the info!!! Got another one for you. Can this be done (might not be the right code but you get the picture)???

If Range("B27") = "" and Range("E11") = 1 Then
MsgBox "Cell B27 is empty and needs to be filled out"
Range("B27").Select
Exit Sub
End If

Basically, if E11 is empty, I don't care if B27 is also empty as I don't require this information.

Thanks!
 
Upvote 0
You lost me - if E11 is empty, you don't care whether B27 has anything in it?
 
Upvote 0
Sorry about the confusion. Let me try this again (with more details)...

If cell E9 is empty, then cells C51 must be empty but if cell E9 equals to 1 (cell can only contain 1, 0 or be empty), then cells C51 must be filled out (if it's not filled out, then I would show the message box saying "Cell C51 must be filled out").

Hope this makes more sence...
 
Upvote 0
So other than the different cell addresses, what was wrong with the code you posted?
 
Upvote 0
It wasn't working so that's why I was asking (giving me an error message) but found my error (**** typos)!!!

What if I want this:

If Sum of cells E9+E10+E11+E13+E15+E16+E17 is lower than 1, then cells C51 must be empty but if Sum of cells E9+E10+E11+E13+E15+E16+E17 is equals or grater than 1, then cells C51 must be filled out (if it's not filled out, then I would show the message box saying "Cell C51 must be filled out").
 
Upvote 0
Code:
If Application.Sum(Range("E9:E17")) < 1 then
   If len(range("C51").Value) > 0 then
      msgbox "C51 should be empty"
      Exit sub
   End If
Else
   If len(range("C51").Value) = 0 then
      msgbox "C51 must be filled out"
      Exit sub
   End If
End If
 
Upvote 0
Thanks but in your code "If Application.Sum(Range("E9:E17")) < 1 then", it will include E12 and E14. I don't want these 2 cells to be included in the SUM.
 
Upvote 0
Code:
Application.Sum(Range("E9:E11,E13,E15:E17"))
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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