tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
In a vlookup, can the range be a collection?
Say I have only two values in cells A1 and A2.
If the range is an array, it works:
but I tried changing from an array to a collection and got an error:
The error message was:
Have I made a mistake with the syntax or can't the range in a vlookup be a collection?
Thanks
<strike>
</strike>
Say I have only two values in cells A1 and A2.
If the range is an array, it works:
Rich (BB code):
Dim MyArray() As Variant
MyArray() = Cells(1, 1).CurrentRegion.Value
Dim g As Integer
g = 2
Dim j As Variant
j = Application.VLookup(g, MyArray(), 1, False)
but I tried changing from an array to a collection and got an error:
Rich (BB code):
Dim MyColl As Collection
Set MyColl = New Collection
Dim i As Integer
For i = 1 To 2
MyColl.Add Cells(i, 1).Value
Next i
Dim g As Integer
g = 2
Dim j As Variant
j = Application.VLookup(g, MyColl, 1, False)
The error message was:
Rich (BB code):
Application-defined or object-defined error
Have I made a mistake with the syntax or can't the range in a vlookup be a collection?
Thanks
<strike>
</strike>
Last edited: