I am perplexed about how it is that the arbitrarily (meaning not apparently connected to anything at all) dimensioned "Dim ArrayStr As Range" is recognised by the "For Each" loop as being each following cell in RangeToSum.
How does VBA know this?
Clearly there is some assumed logic derived from how VBA itself is written in the underlying language; but what is it?
Public Function SumVlookups(ByVal Lookupvalue As Single, ByVal RangeToSum As Range) As Single
Dim ArrayStr As Range
For Each ArrayStr In RangeToSum
If Not IsError(Application.VLookup(Lookupvalue, Evaluate(ArrayStr.Value), 1, False)) Then SumVlookups = SumVlookups + Application.VLookup(Lookupvalue, Evaluate(ArrayStr.Value), 2, False)
I can't help wondering if the "For Each" line is read right to left (backwards), we have a range that contains a series of cells (being the definition of a range) and these cells are named whatever name had been given after the words "For Each", and from there we work further backwards to dimension it with a datatype - or in this case an expected datatype.. kinda, as it's a range and that's not a datatype is it? It's an object is it not?