Consulting

Results 1 to 5 of 5

Thread: Conditional formatting help needed

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Conditional formatting help needed

    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.

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi austenr, not sure what you mean by "fields in a form", but see if this is any use to you

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

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    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

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Thanks johnske that was exactly what I wanted.

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Not a prob, but I only provided the link, it's DRJs work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •