IF blank macro

Yellowdude

New Member
Joined
Mar 4, 2002
Messages
20
I have this formula
If Textbox1 = "" Then
MsgBox "Field must be answered before you can proceed"
Exit Sub
End If

This prevents the next stage when Ok is pressed however th rest of the macro still contiues how do I stop the macro when the cell is blank?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Are you calling this from another Procedure?? The Exit Sub will exit the Procedure it is housed in but go straight back to the calling procedure. You could use

The End statement instead but this would unload the UserForm (if you are using one) and destroy all variables. Use a Boolean at the Project level.

EG
At the very top of a standard module put:

Public bCarryOn as Boolean

Then use:

bCarryOn= True
If Textbox1 = "" Then
MsgBox "Field must be answered before you can proceed"
bCarryOn= True
Exit Sub
End If


And then use a simple If statement in your calling Procedure to Exit that Sub if it's True.
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

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