![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Location: Louisiana USA
Posts: 26
|
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 |
|
Board Regular
Join Date: Feb 2002
Location: Perth Australia
Posts: 1,567
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
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 |
|
New Member
Join Date: Feb 2002
Location: Louisiana USA
Posts: 26
|
Thanks Guys. Works perfect...
Sam |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|