28 April 2022
VBA ArrayList - A Complete Guide - Excel Macro Mastery
by cascamortoContents :
1 Quick Guide to the VBA ArrayList
2 Description
3 Download the Source Code
4 Declare and Create the VBA ArrayList
4.1 Late Binding
4.2 Early Binding
4.3 VBA ArrayList Automation Error
5 Adding Items to the VBA ArrayList
6 Reading through an ArrayList
7 Sorting
8 Cloning the VBA ArrayList
9 Copying from an VBA ArrayList to an Array
10 Writing Directly to a Range
11 Array to a VBA ArrayList(1D)
12 Remove All Items from the ArrayList
13 What’s Next?
20 April 2022
[vba] -- return an ArrayList from a function
by cascamortoHello Paul
Is there a way to return an ArrayList from a function, like a bellow?
This is the code I have implemented
Public Function ReturnArrayList() As ArrayList // or return type As Variant
Dim alist As ArrayList
Set alist = New ArrayList // Early Binding
alist.Add “a”
alist.Add “b”
alist.Add “c”
alist.Add “240”
ReturnArrayList = alist
End Sub
Sub GetArrayList()
Dim alist As ArrayList
alist = ReturnArrayList()
MsgBox alist(0)
End Sub
Thank you,
Nishan
Reply
Paul Kelly
Paul Kelly on December 24, 2019 at 7:56 am
Hi Nishan,
You need to use Set when returning an object.
1
(3 marks)