The default Range property gives unexpected results.

As a follow-up answer to the question I posted here , I would like to know why the following is not an error, is this possible in VBA error?

Take the following data:

example data set
If we use the following VBA code, we will get an error because we need to use a numeric date value to match:

'//Produces error  
Debug.Print WorksheetFunction.Match(Range("C3").Value, Range("A1:A14"), 0)

and therefore any of these operators 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 do not specify a property, it also works:

Debug.Print WorksheetFunction.Match(Range("C3"), Range("A1:A14"), 0)

So, if it .Valuedoesnโ€™t work, and this is the default property of the object Range- why does it work in the above example?

? - , ?

+4
1

, . :

Debug.Print Range("C3"), Range("C3").Value, Range("C3").Value2

.

3/2/2015 3/2/2015 42065

Value Range Object.
, Value , .

Debug.Print WorksheetFunction.Match(Range("C3").Value, Range("A1:A14").Value, 0)

, , .

Value , Excel , , Values. , , Excel , .

+1

All Articles