Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Message Box for wrong date entered

  1. #1
    New Member
    Join Date
    Feb 2002
    Location
    Louisiana USA
    Posts
    26
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I need a message box to appear to let the user know that if the date that the user is entering is more than 12 months from the last date entered.
    There will be two cells used for date on the worksheet. One cell will be a previous date and the other cell will be the date being entered.
    I need a Macro that will look at the previous date and compare it to the date being entered. If the date being entered is in excess of 12 months a pop up window will let the user know.

    Thanks, Sam

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    Perth Australia
    Posts
    1,584
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Sam

    Copy this code.
    Right mouse select the sheet tab and select View Code.
    Paste the code in the large white expanse.
    Use Alt+F11 to return to your worksheet.
    A1 contains first date
    B1 contains second date entry
    Message will appear if 2nd date entry exceeds first by 365 days.
    Change cell references to the cell locations you wish to use for your dates.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$1" Then
    If Range("B1").Value - Range("A1").Value > 365 Then
    MsgBox "Date entered is more than 12 months since previous date"
    End If
    End If
    End Sub

    You might also try using Data Validation on B1 to force use of correct date.

    Hope this helps
    Derek


  3. #3
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You can also use the Datediff function, useful if you want other periods of time to be tested (quarters, months, etc.): -

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 2 Then Exit Sub
    If DateDiff("d", Target.Offset(0, -1), Target.Value) > 365 Then MsgBox ""

    End Sub

    [ This Message was edited by: Mudface on 2002-02-21 06:25 ]

  4. #4
    New Member
    Join Date
    Feb 2002
    Location
    Louisiana USA
    Posts
    26
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Guys. Works perfect...
    Sam

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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