Consulting

Results 1 to 9 of 9

Thread: Macro to check dates and notify user

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    8
    Location

    Macro to check dates and notify user

    Hello,
    I was wondering if it is possible to run a macro when the user opens the spreadsheet that Checks all the dates in A1:A50. Then if the date is not todays date or further into the future then it warns the user/prompts for the date to be changed.
    Any help is much appreciated.
    Thank you,
    Greg.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Something like this in the Workbook Open event should get you started.

    Dim i As Long
    For i = 1 to 50
    If Sheets("Sheet1").Range("A" & i).Value < Date Then
    MsgBox "Change the date."
    Exit For
    End If
    Next i

  3. #3
    VBAX Regular
    Joined
    Jul 2005
    Posts
    8
    Location
    That's a great start, thanks! How do I make it so that it ignores cells that do not yet have any values?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Hobb3s
    That's a great start, thanks! How do I make it so that it ignores cells that do not yet have any values?
    Dim i As Long
    For i = 1 To 50
        With Sheets("Sheet1").Range("A" & i)
            If .Value <> "" Then
                If .Value < Date Then
                    MsgBox "Change the date."
                    Exit For
                End If
            End If
        End With
    Next i

  5. #5
    VBAX Regular
    Joined
    Jul 2005
    Posts
    8
    Location
    Thanks for the quick response, I just figured it out this second..

    Private Sub Workbook_Open()
    Dim i As Long
    For  i = 4 To 54
        If Sheets("Sales").Range("H" & i).Value  < Date And Sheets("Sales").Range("H" & i).Value <> 0  Then
            MsgBox "Fix the date  please"
            Exit  For
        End If
    Next i
    End Sub
    It seems to work that way.. I really need my work to get me a vba in excel for dummies book or something to help me with the simple stuff.
    Thanks guys!

  6. #6
    VBAX Regular
    Joined
    Jul 2005
    Posts
    8
    Location
    One more quick question.. how do I return the name and/or value of the cell that is the problem... maybe highlight it on the sheet as well.

  7. #7
    VBAX Regular
    Joined
    Jul 2005
    Posts
    8
    Location
    ok, I figured it out.. found an online resource that explains some of the simpler stuff.. like syntax. Appreicate all the help.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Hobb3s
    One more quick question.. how do I return the name and/or value of the cell that is the problem... maybe highlight it on the sheet as well.

    With Sheets("Sheet1").Range("A1:A50")
            .FormatConditions.Delete
            .FormatConditions.Add Type:=xlExpression, _
                                  Formula1:="=AND(A1<>"""",A1<TODAY())"
            .FormatConditions(1).Interior.ColorIndex = 38
        End With

  9. #9
    No more issues?
    A mighty flame followeth a tiny sparkle!!



Posting Permissions

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