This post is intended to share the undocumented product feature for future use as per this blog post.
I found an unexpected behavior of some Excel's functions when they are called from VBA. They change some data types:
Sub test1()
Dim ou, tu, soa, j&: ReDim ou(1 To 2, 1 To 2), soa(1 To 2, 1 To 1)
For j = 1 To 2
ou(j, 1) = j: ou(j, 2) = Now(): soa(j, 1) = j
Next
With Application
Debug.Print "Expected:", TypeName(ou(1, 1)), TypeName(ou(1, 2))
tu = .Sort(ou, 2)
Debug.Print "Sort:", TypeName(tu(1, 1)), TypeName(tu(1, 2))
tu = .XLookup(1, soa, ou)
Debug.Print "Xlookup:", TypeName(tu(1)), TypeName(tu(2))
tu = .VLookup(1, ou, 2, False)
Debug.Print "Vlookup:", , TypeName(tu)
End With
End Sub
-->
Expected: Long Date
Sort: Double String
Xlookup: Double String
Vlookup: String
So, it changes Long to Double and Date to String. Be aware of it!
Considering this bug as a feature, how can we suppress it's effect?
UPD
Additional functions falling into this feature: IfError, IfNa, Lookup, HLookup, Filter, Choose. It looks like all functions expected to return argument values unchanged falling into this feature.