Phil
Place code in the Thisworkbook object
1) Alt F11
2) Ctrl R
3) double click Thisworkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("yourSheet").[a1] = "" Then
Cancel = True
MsgBox "Can't save No entry for A1"
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Sheets("yourSheet").[a1] = "" Then
Cancel = True
MsgBox "Can't save No entry for A1"
End If
End Sub
Ivan
Ivan (or anyone),
How would you do this for required checkboxes and option boxes? (Forms type)
Thanks,
David
Question: Once you have this code in place how do you save your Worksheet? It needs to be saved with empty cells and code in place. Is this a catch-22?
Thanks.
David
Not at all...just put in a test or password string
and delete it upon saving via code...eg
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("yourSheet").[a1] = "" Then
If Sheets("yourSheet").[iv1] <> "save" Then
Cancel = True
MsgBox "Can't save No entry for A1_BC"
End If
Else
MsgBox "BC"
Sheets("yourSheet").[iv1] = ""
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Sheets("yourSheet").[a1] = "" Then
If Sheets("yourSheet").[iv1] <> "save" Then
Cancel = True
MsgBox "Can't save No entry for A1_BS"
End If
Else
Application.EnableEvents = False
MsgBox "BS"
Sheets("yourSheet").[iv1] = ""
End If
Application.EnableEvents = True
End Sub
Private Sub Workbook_Open()
Sheets("yourSheet").[iv1] = ""
End Sub
Something like this will get you started.....
Lookup QueryClose
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Prevent user from closing if Checkbox is not checked.
If CloseMode = 0 Then
If CheckBox1.Value = False Then
Cancel = 1
MsgBox "Checkbox not Ticked!"
End If
End If
End Sub Ivan (or anyone), How would you do this for required checkboxes and option boxes? (Forms type) Thanks,
It works!!
Thanks everyone for your time and effort
Phil