Dates in arrays

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Something doesn't seem to be quite right with my dates in arrays.

Put a date of 02/01/1900 in cell A1, put a date of 03/01/1900 in cell B1.

Format both to be dates, (choose the type to be 14/03/2001).

If I step into my code and look at the locals window, it says:

Code:
MyArray(1,1) has a value of #01/01/1900#
MyArray(1,2) has a value of #02/01/1900#


Code:
Option Explicit

Sub Test()

Dim MyArray() As Variant

MyArray = Cells(1, 1).CurrentRegion.Value

End Sub

Why is it showing the dates out by a day?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Excel's date formulas allow for 29/2/1900 (because Lotus did) even though it didn't exist. VBA does not do this, which means that date values in VBA pre 1st March 1900 are one day out compared to their worksheet equivalents.
 
Upvote 0
Hi,

It's a feature in Excel. Excel was created with a deliberate bug where 1900 was made a leap year; it isn't, so all dates prior to 1 Mar 1900 are 1 day out. This was done because Excel was trying to compete with Lotus 123 as a spreadsheet package and Lotus 123 had a genuine bug where it thought 1900 was a leap year. Put dates from 1 Mar 1900 and it will work fine.

have a look at this link, it's for an older version of Excel but still valid.


https://support.microsoft.com/en-us/kb/214326
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top