before save/close

3earth

New Member
Joined
Mar 21, 2010
Messages
17
Would like code to not allow save or close if cells P9 through R27 have ? Instead of blank. Thank you for any assistance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

Why would those cells have a "?" in them? What if they're blank?

Here's a start:

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_BeforeClose(Cancel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)<br>    <SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range("P9:R27")<br>            <SPAN style="color:#00007F">If</SPAN> c.Value = "?" <SPAN style="color:#00007F">Then</SPAN><br>                Cancel = <SPAN style="color:#00007F">True</SPAN><br>                MsgBox "Data missing in Range P9:R27"<br>                <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>            <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>        <SPAN style="color:#00007F">Next</SPAN> c<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,
 

3earth

New Member
Joined
Mar 21, 2010
Messages
17
I have this formula in each of those cells =IF(S9>0.01,"?","") so that the person entering data will see that data is required. Each has a drop down list to choose from using Data Validation.

The code still allows me to save without stopping and close without stopping if ? is in any of those cells. I copied the code and placed in Workbook. Do I need to do another step?
 
Last edited:

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
How do you have Data Validation & a formula in those cells?

Note that on testing, the code picks up a "?" as the result of a formula.
 

3earth

New Member
Joined
Mar 21, 2010
Messages
17
If blank, I want the user to be able to save/close. I did not know that it was odd to have a formula and data validation in one cell. But I do have both. I input the formula and then added Data Validation to be able to have the drop down list of Y or N and input messagae explaining what will happen if Y or N is picked. Yes, ? should be in the field if S9 (this goes to S27) is greater than 0.01. If 0, blank.

This is a type of order form for employees to request purchasing. I would attach the file but I can't figure that out right this second. :)
 

3earth

New Member
Joined
Mar 21, 2010
Messages
17
I don't know what I did differently, but this code works. I copied it and added beforesave also so that the user has to complete the fields properly before being able to close or save the file. Thank you so much for your help with this. Now this form is going to work for me not against me. :pray: Thank you so much!!!!
 

Forum statistics

Threads
1,144,389
Messages
5,724,073
Members
422,534
Latest member
ThiccNugg

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