64 bit Excel VBA has a nasty habit of converting array dates to numbers when that array is assigned to a range. 32 bit VBA, on the other hand, preserves the date format.
Here's a quick bit of example code to demonstrate the different date handling:
Sub test()
Dim arr(0 to 1) As Variant
arr(0) = "Text"
arr(1) = #9/12/2007#
ActiveSheet.Range("A1:B1") = arr
End Sub
(Note that the dates are not converted in 64 bit Excel if a single date value is used; it is necessary to have the first text value present)
When run in 32 bit Excel, the output is Text, 9/12/2007
When run in 64 bit Excel, the output is Text, 39337
It is as though 64 bit VBA only uses the Value2 property for all range objects.
How can I get 64 bit VBA to behave like 32 bit VBA without writing a function to handle all array writes?
Just to head off a possible well-intentioned response: I am aware that the underlying formula remains the same between those cells. 32 bit Excel, however, automatically sets the proper cells to a date format which greatly simplifies my code.
DATEDIFF function in VBA is an inbuilt function in VBA which is also categorized under date and time function in VBA, this function is used to get the difference between two dates, this function takes three arguments the first argument is what part of the difference we want which can be year days or months or seconds ...
Click on the Manage Microsoft 365 button and then click Install Apps to present the Install Office 365 screen. Click the Other Options link at the top right to choose a specific version of Office. Select Office - 32-bit or Office - 64-bit, then complete the install process.
I had a problem like this earlier and resolved it by ensuring that the cell format was always set to a date format.
Something like this should do the trick:
Range("A1").Select
Selection.Format = "long date"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With