PDA

View Full Version : [SOLVED] Conditional formatting help needed



austenr
10-30-2004, 01:36 PM
I need some VBA code that will check the fields in a form for entries and if they are blank display an error message and not let the user continue with either: a) printing the worksheet (this is a form I made in EXCEL) or b) saving the form. I have searched the knowledge base and cannot find it. Any help would be appreciated.

johnske
10-30-2004, 02:35 PM
Hi austenr, not sure what you mean by "fields in a form", but see if this is any use to you :bink:

http://www.vbaexpress.com/forum/showthread.php?t=693

Jacob Hilderbrand
10-30-2004, 02:35 PM
How about something like this:


Option Explicit

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim CheckRange As Range
Dim Cel As Range
Set CheckRange = Sheet1.Range("A1:A10")
For Each Cel In CheckRange
If Cel.Value = vbNullString Then
MsgBox Cel.Address(False, False) & " is blank. Please complete the form."
Cancel = True
Exit Sub
End If
Next
End Sub

austenr
10-30-2004, 05:09 PM
Thanks johnske that was exactly what I wanted.

johnske
10-30-2004, 07:04 PM
Not a prob, but I only provided the link, it's DRJs work :bink: