Check for missing cells before allowing it to be saved

bdhobbs1

Banned user
Joined
May 22, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I'm not very good with VBA and Macros. I've google and tried many different formulas, no luck.

I've got an excel spreadsheet where I need several fields to have data entered in them before allowing a save to take place.

My boss wants it to check for blank fields before you click the share button, I'm not sure that can be done.

Only 1 worksheet... the share button is going to be used by the Operator who will send it to the Supervisor.

Thanks for any input you give me.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
The following checks two cells for content. If either or both are empty, the user cannot close the workbook.
You can add more cells to the list in the macro to match your project, as well as edit to have it more conform
to your needs. The code goes in the THISWORKBOOK module.

VBA Code:
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    If Sheet1.Range("A2").Value = "" Or Sheet1.Range("C2").Value = "" Then
        MsgBox "You missed something !", vbCritical, "Error"
        Cancel = True
    End If

End Sub
 
Upvote 0
The following checks two cells for content. If either or both are empty, the user cannot close the workbook.
You can add more cells to the list in the macro to match your project, as well as edit to have it more conform
to your needs. The code goes in the THISWORKBOOK module.

VBA Code:
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
   
    If Sheet1.Range("A2").Value = "" Or Sheet1.Range("C2").Value = "" Then
        MsgBox "You missed something !", vbCritical, "Error"
        Cancel = True
    End If

End Sub

Thanks, but what about a before save option instead of a before close?
My worksheet is called Operator and the range is BA32 to BA41 if that helps you.
 
Upvote 0
The same module has a Before Save feature as well :

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

End Sub

You can put the macro inside there and paste it to the THISWORKBOOK module.


If you have cross posted your request for assistance on other forums, you must provide the links to those posting here and on the other forums as well. Rules.
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Check for missing cells before allowing it to be saved
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Thanks for the replies, I just can't get anything to work on my end.
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Also Cross posted at: Check for missing data in cells before saving
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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