PDA

View Full Version : Macro to compare date in cell to current date.



javeed
10-17-2015, 01:08 PM
Hi,
In cell (A1) "Report Date:18-10-2015" Category General as data is from text file.
Macro to check this date with system date if wrong then alert message of wrong date.
Any help would be greatly appreciated!

p45cal
10-17-2015, 06:39 PM
Sub blah()
y = Split(Split(Range("A1").Value, ":")(1), "-")
If DateValue(Join(Array(y(2), y(1), y(0)), "-")) = Date Then
MsgBox "It IS today"
Else
MsgBox "It's not today!"
End If
End Sub

SamT
10-17-2015, 07:24 PM
Why the double Split?

Wouldn't this work?
Sub blue()
y = Split(Range("A1").Value, ":")
If DateValue(y(1)) = Date Then
MsgBox "It IS today"
Else
MsgBox "It's not today!"
End If
End Sub

javeed
10-17-2015, 11:27 PM
Hi,

Thank you P45cal and SamT.

p45cal
10-18-2015, 02:54 AM
Why the double Split?Because of a recent conversation (with you!) at http://www.vbaexpress.com/forum/showthread.php?53987-Change-Data-from-String-to-Date-Runtime-Error-1004&p=332203&viewfull=1#post332203

SamT
10-18-2015, 01:22 PM
DOH! How soon we (I) forget. Nice "universal" solution.