V.B.A.02
07-28-2017, 03:41 AM
Hello Everyone,
I have just come across below strange behavior of excel VBA and just trying to understand why is this happening, Please see below code:
Sub DateVarTest()
Dim Dt1, Dt2, Dt3 As Date
Dt1 = "": Dt2 = "": Dt3 = ""
Dt1 = Date
Dt2 = Date + 1
Dt3 = Date + 2
'Further Codes
End Sub
As soon as I start running code step by step using F8 key, I see by hovering mouse on variables Dt1, Dt2 and Dt3 that Dt1 and Dt2 are empty but Dt3 has value as "12:00:00 AM".
Strange thing is that if I add one more variable Dt4 and then what I observe is that Dt1, Dt2 and Dt3 are now shown empty but Dt4 (which is last variable declared as date) shows value as "12:00:00 AM".
** If I had just one variable it would have value as "12:00:00 AM". but with multiple variables as date, only last variable has value as "12:00:00 AM" others are just empty.
Can anyone help me understand this strange behavior of VBA?
Thanks for Help.!
I have just come across below strange behavior of excel VBA and just trying to understand why is this happening, Please see below code:
Sub DateVarTest()
Dim Dt1, Dt2, Dt3 As Date
Dt1 = "": Dt2 = "": Dt3 = ""
Dt1 = Date
Dt2 = Date + 1
Dt3 = Date + 2
'Further Codes
End Sub
As soon as I start running code step by step using F8 key, I see by hovering mouse on variables Dt1, Dt2 and Dt3 that Dt1 and Dt2 are empty but Dt3 has value as "12:00:00 AM".
Strange thing is that if I add one more variable Dt4 and then what I observe is that Dt1, Dt2 and Dt3 are now shown empty but Dt4 (which is last variable declared as date) shows value as "12:00:00 AM".
** If I had just one variable it would have value as "12:00:00 AM". but with multiple variables as date, only last variable has value as "12:00:00 AM" others are just empty.
Can anyone help me understand this strange behavior of VBA?
Thanks for Help.!