I have an Excel-2003 spreadsheet that has several fields but absolutely requires 4 specific fields to not be blank before "SAVE" or "PRINT".
I HAVE NO VB EXPERIECE WHATSOEVER SO PLEASE KEEP YOUR ANSWERS VERY SIMPLE!
I did a search on this topic, found a prior post regarding this subject and did a copy/paste of the VB code to my sheet. The result is that the code works BUT I can't save the sheet because I get an error message that the field is required. In this initial test I only used one field but eventually 3 more need to be validated.
The following code I what I copied from a prior post and which looks very complicate:
open the vb editor with ALT + F11
-in the left pane doubleclick thisworkbook icon
-then paste this code
Option Explicit
Private Sub Workbook_BeforeClose(Cance
l As Boolean)
if not CheckDateField then
MsgBox "you need to fill in a end date to proceed"
Cancel = true
end if
End Sub
Private Sub Workbook_BeforePrint(Cance
l As Boolean)
if not CheckDateField then
MsgBox "you need to fill in a end date to proceed"
Cancel = true
end if
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
if not CheckDateField then
MsgBox "you need to fill in a end date to proceed"
Cancel = true
end if
End Sub
Private Function CheckDateField() as Boolean
CheckDateField=False
If Worksheets(1).Range("C1").
Value <> "" Then
CheckDateField=True
end if
End Function
-you've to change the line with Worksheets(1).Range("C1").
Value
-to the field you need to check
-then save and close the editor
then try it out
Start Free Trial