Cyberdude
05-21-2005, 02:12 PM
I just encountered a peculiar discrimination.
I wanted to extract a date from a cell, then include it in a Msgbox display. The cell has the date displayed as "mm/dd/yy". Note that there are just 2 year digits.
My VBA code looked like:
BillDate = Range("A1")
Msgbox "This is the date: " & BillDate
What is displayed is
This is the date: 05/22/2005 (A 4-digit year)
So I altered my code above to look like:
BillDate = Format(Range("A1"), "mm/dd/yy")
Msgbox "This is the date: " & BillDate
and I got the same results with a 4-digit year. So I changed the code to be:
BillDate = Range("A1")
Msgbox "This is the date: " & Format(BillDate, "mm/dd/yy")
and it worked!
Why is it that I can't format the date when putting it into a string variable, then display it, but it works when I format it in the Msgbox statement??
I wanted to extract a date from a cell, then include it in a Msgbox display. The cell has the date displayed as "mm/dd/yy". Note that there are just 2 year digits.
My VBA code looked like:
BillDate = Range("A1")
Msgbox "This is the date: " & BillDate
What is displayed is
This is the date: 05/22/2005 (A 4-digit year)
So I altered my code above to look like:
BillDate = Format(Range("A1"), "mm/dd/yy")
Msgbox "This is the date: " & BillDate
and I got the same results with a 4-digit year. So I changed the code to be:
BillDate = Range("A1")
Msgbox "This is the date: " & Format(BillDate, "mm/dd/yy")
and it worked!
Why is it that I can't format the date when putting it into a string variable, then display it, but it works when I format it in the Msgbox statement??