I am attempting to implement what Microsoft is calling out as a best practice, but with no avail. This is due to the newly support Dynamic Arrays that is now supported within excel. This is their article and below is the specific section. HERE
Best Practice
If targeting DA version of Excel, you should use Range.Formula2 in preference to Range.Formula.
If targeting Pre and Post DA version of Excel, you should continue to use Range.Formula. If however you want tight control over the appearance of the formula the users formula bar, you should detect whether .Formula2 is supported and, if so, use .Formula2 otherwise use .Formula
Within VBA how is it possible to detect the version (Pre DA or Post DA)?
I have have created macros in excel that all work great in the older version of excel but once the new versions were introduced the formulas were changing because it was relying on what was the previous default "Implicitly Intersection Evaluation (IIE)". Due to the superseded method in the newer versions of excel all of the VBA implementations rely on the old method and the new excel adds the Implicit Intersection operator @
to the formulas. Because there is a risk that this will break the complicated sheets I want to be able to detect IF the current version of excel supports Dynamic Arrays, and if so I want to be able to have all of the implementations of range.formula
replaced with range.formula2
.
‘Detect Pre or Post DA version
Dim ExcelVersion As Variant
ExcelVersion = blabla bla test ‘Some test function HERE, return vbTrue if Post DA Version Enabled
If ExcelVersion = vbTure Then
Range.Formula2 = "=CustomFunction("& variable & ")"
Else
Range.Formula = "=CustomFunction("& variable & ")"
End If
*vbTure is used above as an example it can be anything, same with "variable"