Search unlocked cells, if empty, don't allow document to be saved

jarzack

New Member
Joined
Jun 14, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Beginner help needed.

I have a worksheet used for user inputs. This worksheet is Protected and the user will only be able to input data into unlocked cells. I need a way to search all unlocked cells are empty, if yes then not allow the document to be saved.

How do I do this?
 
You can add this script to "Workbook/BeforeSave" inside VBA for ThisWorkBook:

VBA Code:
Dim ce As Range
Dim M As Double
 For Each ce In ActiveSheet.UsedRange ' Change it to desired worksheet
 If ce.Locked = False And ce = "" Then
 M = M + 1
 End If
Next
If M > 0 Then
Cancel = True
MsgBox "This workbook cannot be saved, you have to fill up all cells required!"
Else
Cancel = False
End If

Here:
 

Attachments

  • 123.png
    123.png
    30.4 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,917
Members
453,766
Latest member
Gskier

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