VBA handles dates differently in Excel 2016? Is there any documentation about this?

It seems that VBA was changed in Excel 2016/2013 as it starts throwing errors in places where it does not drop Excel 2010.

The code below does the following:

  • Creates 17 dates in the first row of ActiveSheet
  • populates a date array, with 4 values
    • one in the first line
    • one is not in the first row
    • alone in 1913
    • one until 1904
  • he searches for each value and colors the cell red if it is found;

In Excel 2010, it runs smoothly, finding one value and not searching for the other 3 as expected. Everything is good.

In Excel 2016/2013, it becomes a displeased value until 1904 and throws an error

Invalid procedure call or argument (Error 5)

on Set foundRange = Rows(1).Find(someDates(cnt)) .

So it seems that in Excel 2016/2013, according to Date1904, there is some check that does that 04.01.1900 until the year 1904 and therefore it cannot be parsed with a date in the Excel date system? Although in Excel 2010 this is not so.

So the question is - Is this function / behavior documented?

 Public Sub TestMe() ThisWorkbook.Date1904 = True Cells.Clear 'clearing up all. Dim cnt As Long For cnt = 3 To 20 Cells(1, cnt) = DateAdd("M", cnt, DateSerial(2016, 1, 1)) Cells(1, cnt).NumberFormat = "MMM-YY" Next cnt Dim someDates(3) As Date someDates(0) = DateSerial(2016, 1, 1) 'exists someDates(1) = DateSerial(2012, 1, 1) 'does not exist in the range someDates(2) = 5000 '08.09.1913 (in VBA) someDates(3) = 5 '04.01.1900 (in VBA) Dim foundRange As Range For cnt = LBound(someDates) To UBound(someDates) Set foundRange = Rows(1).Find(someDates(cnt)) 'Error 5 in Excel 2016 If Not foundRange Is Nothing Then foundRange.Interior.Color = vbRed End If Next cnt ThisWorkbook.Date1904 = False 'all dates with 4 years back End Sub 

Why November 2016 was selected when searching in January 2016 - Range. Do not assume that the difference between January and November (February and December) in VBA Excel

+8
date vba excel-vba excel version
source share

No one has answered this question yet.

See similar questions:

4
Range.Find doesn't make the difference between January and November (February and December) in VBA Excel
2
Find Date () with Application.Match ()
one
If the date is greater than or equal to, then the function

or similar:

1350
Where can I find date formatting documentation in JavaScript?
705
Calculate the difference between two dates (number of days)?
502
How to avoid using Select in Excel VBA
456
Is there a way to crack a password in an Excel VBA project?
4
Range.Find doesn't make the difference between January and November (February and December) in VBA Excel
one
Excel VBA with matches and index
one
Excel maximum value based on date range
one
Excel 2016 VBA not writing to unlocked cell
one
Excel 2016 breaks previously running VBA macro
0
how to cut an array of rows of a vlookup table in excel vba

All Articles