VBA to prevent saving in worksheet if certain cells are empty but not for administrator / creator

Anandpersad

New Member
Joined
Oct 18, 2014
Messages
31
Hi All,

I have the following VBA, which prevent the user from saving the file without filling in the mandatory fields.
The problem is, even I as creator of the VBA cannot save the file without entering data in those cells.
Can you help me with a VBA to avoid this.
So, the user of the file should always fill in the mandatory field before he/she can save the file, but the creator of the file can save without filling in the mandatory file.
I was thinking of a password protection. Only those who has the password can save without filling in he mandatory fields.
But I am also open for any other solution.
My VBA is as follows:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Disables saving unless user fills in required cells
Dim CheckC As Range
Set CheckC = Range("H9")
If CheckC.Value = "" Then
MsgBox "Cell H9 Check", vbCritical, "Incomplete Entry"
CheckC.Select
Cancel = True
End If
Set CheckC = Range("H10")
If CheckC.Value = "" Then
MsgBox "Cell H10 check", vbCritical, "Incomplete Entry"
CheckC.Select
Cancel = True
End If
End Sub

<tbody>
</tbody>

Thanks
Anandpersad
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You could add this line immediately after your Dim statement:
Code:
If Environ("UserName") = "Put your user name between these quote marks" Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,214,552
Messages
6,120,172
Members
448,948
Latest member
spamiki

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