Results 1 to 8 of 8

Thread: Required fields, validate on save

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,446
    Location
    It is pretty straight-forward. You would use the BeforeSave workbook event to check all of the fields, and add colour where appropriate, not saving if any incompletes.

    Something like

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
        Dim LastRow As Long
        Dim vecColours As Variant
        Dim fErrors As Boolean
        Dim i As Long
        Dim j As Long
        vecColours = Array(xlColorIndexNone, 25, 28, 39, 40, 37) 'different colours for different columns
        With Me.Worksheets("Master")
            ' handle dynamic number of projects
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row    'column A is server name
            For i = 2 To LastRow
                ' clear it down first
                .Range("A2").Resize(LastRow, 5).Interior.ColorIndex = xlcolorindexnon
                ' assume 5 columns of data
                For j = 2 To 5
                    If .Cells(i, j).Value = "" Then
                        .Cells(i, j).Interior.ColorIndex = vecColours(j - (LBound(vecColours) + 1))
                        fErrors = True
                    End If
                Next j
            Next i
            If fErrors Then
                MsgBox "You have invalidate input"
                Cancel = True
            End If
        End With
    End Sub
    To be more helpful, we would need more details.
    Last edited by Aussiebear; 04-26-2025 at 07:01 PM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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