Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim password As String
password = "mypassword"
Dim rng As Range
If SaveAsUI = False Then
MsgBox "Please save the file using SaveAS."
Cancel = True
Exit Sub
End If
If WorksheetFunction.CountA(Range("P19,P29,P31")) < 3 Then
If MsgBox("One or more cells in P19,P29 and P31 is missing data. Do you wish to save with the data missing?", vbYesNo) = vbYes Then
password = InputBox("Please enter your password to save the file.", "Enter Password")
If password <> "mypassword" Then
MsgBox ("Invalid password. Please try again.")
Cancel = True
Exit Sub
ElseIf password = "mypassword" Then
'
End If
Else
For Each rng In Range("P19,P29,P31")
If rng = "" Then
MsgBox ("Before saving, you must enter a value in cell " & rng.Address(0, 0) & ".")
rng.Select
Cancel = True
Exit Sub
End If
Next rng
End If
End If
End Sub