Copying


Copying Arrays

To assign one array to another, you must individually assign the elements, for example
If ArrayName1 and ArrayName2 are both defined as arrays then both the following are valid:

Dim ArrayName1() As String 
Dim ArrayName2() As String

ArrayName1 = ArrayName2
ArrayName1() = ArrayName2()

Copying to a Collection

A Collection object can also be used although to populate the collection you need to loop through the array.
This might be a good solution if you need to perform multiple searches in the same data set.

Public Function UsingCollection(ByVal arValues As Variant, _ 
                                ByVal sFindValue As String) _
                                As Boolean
Dim MyCollection As VBA.Collection
Dim lposition As Long
Dim sreturn As String
   
   On Error GoTo AnError
   Set MyCollection = New VBA.Collection
   For lposition = 0 To UBound(arValues)
      MyCollection.Add arValues(lposition), arValues(lposition)
   Next lposition
   sreturn = MyCollection.Item(sFindValue)
   UsingCollection = True
   Exit Function

AnError:
   UsingCollection = False
End Function

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext