0

I have a date (format m/d/yyyy) stored in a Label1.Caption. I'm trying to run a simple condition to compare it to the actual time, but doesn't seems to work :/

My code is:

Label1.Caption = "1/5/2016"
If Label1.Caption > Now Then
'Do something
End if

Like this is it should be going into the if, but is not. Can you please help me out? Cheers, G

Gonzo
  • 53
  • 6
  • 1
    you probably need to convert the caption-string to a date-object using CDate, http://stackoverflow.com/questions/24944662/difference-between-datevalue-and-cdate-in-vba – Rolf Rander Dec 03 '15 at 12:31
  • See [Excel VBA - Convert Text to Date?](http://stackoverflow.com/questions/20375233/excel-vba-convert-text-to-date). –  Dec 03 '15 at 13:00

1 Answers1

0

Cdate can convert string to Date type

Cdate(Label1.Caption)

But 1/5/2016 is quite confusing, macro will based on date format setting in Computer to define, whether mm/dd/yy or dd/mm/yy.

Recommend, involve some text like Jan 5 2016 or 1 May 2016

Eric K.
  • 814
  • 2
  • 13
  • 22