Confirming certain fields have entries before a form can be e-mailed

Godot60

Board Regular
Joined
May 11, 2017
Messages
62
I have an excel form that has certain required fields (more than one) which must have data entered into them. I have created a button that emails the form to me using a VBA statement. Is there a way to prevent the form from being submitted if any of the required cells are left blank? Any assistance would be appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hello,

When I learned how to program in VBA, my teacher always asked that we had a "validation" part before the real code start.
When the validation wasn't correct, it will automatically exit the sub and didn't write stuff in Excel or create Word/PDF or send email.

Some validation can be very simple and I think it would be a good solution for your problem.

Code:
If isempty(textbox1) then
msgbox "Plz fill box1"
Exit sub
End if
 
Upvote 0
This worked great on one cell ! Any idea how to add more cell references to the statement so that it checks them as well? Thanks for your help.
 
Last edited:
Upvote 0
What are talking about for "the statement"?

If it's this simple test, you can have the following or simply copy paste it as much as you need.

Code:
[COLOR=#333333]If isempty(textbox1) OR isempty(textbox2) OR isempty(textbox3) then
[/COLOR]msgbox "Plz fill correctly this userform"
Exit sub
End if
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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