As a follow-up question to an answer I posted here I would like to know why the following doesn't error, is this a possible bug in VBA?
Take the following data:
If we use the following VBA code, we will receive an error because we need to use the numeric value of the date to match:
'//Produces error
Debug.Print WorksheetFunction.Match(Range("C3").Value, Range("A1:A14"), 0)
and so either of these statements will work:
'// Cast to Long
Debug.Print WorksheetFunction.Match(CLng(Range("C3").Value), Range("A1:A14"), 0)
'// Access .Value2 property directly
Debug.Print WorksheetFunction.Match(Range("C3").Value2, Range("A1:A14"), 0)
However as pointed out by Jean-François Corbett, if we don't specify a property it also works:
Debug.Print WorksheetFunction.Match(Range("C3"), Range("A1:A14"), 0)
So if .Value
doesn't work, and this is the default property of the Range
object - why does it work in the above example?
Could this be a bug? Or is there some level of evaluation taking place that counteracts this?