Excel VBA - ArrayList (Clear, Contains and IndexOf Methods)

Опубликовано: 03 Апрель 2026
на канале: The World Of Algorithms
1,630
like

ArrayList in Excel VBA is a class used to create an array of values. ArrayList is more flexible than native array because it's dynamic and it contains much richer functionality. It is in an external library.

Let's answer a few questions about ArrayList.

❓ 1️⃣ How to create the ArrayList ?
👉 You can create the ArrayList using early and late binding

❓ 2️⃣ How to create the ArrayList using late binding ?
👉 There is no need to activate a special library for this. All you have to do is use the simple form below:

Dim arr as Object (arr is a variable used in the video)
Set arr = CreateObject("System.Collections.ArrayList")

❓ 3️⃣ How to create the ArrayList using early binding ?
👉 To use this form, you need to perform several operations. These are those operations:

Step 1. Open the Viual Basic Editor (ALT+F11)
Step 2. Click Tools
Step 3. Click References
Step 4. Scroll down the list, tick the mscorlib.dll checkbox and click OK

After that, the following code should be written:

Dim arr as new ArrayList (arr is a variable used in the video)

❓ 4️⃣ How to clear (remove) all the elements from the ArrayList ?
👉

Dim arr as new ArrayList (early binding)
--------------------
--------------------
arr.Clear

❓ 5️⃣ How to check if item exists ?
👉

Dim arr as new ArrayList (early binding)
--------------------
--------------------
arr.Contains(ItemName)

❓ 6️⃣ How to find the position of an item in the ArrayList ?
👉

Dim arr as new ArrayList (early binding)
--------------------
--------------------
arr.IndexOf(ItemName, Position to start searching from)

------------------------------------------------------------------------------------------
Buy a Cofee ☕ for theworldofalgorithms: https://ko-fi.com/theworldofalgorithms

🥰Thank you for the donation. I am deeply grateful for your help!🥰
------------------------------------------------------------------------------------------

#excel
#msexcel
#vba
#excelvba
#microsoftexcel
#tutorial
#exceltutorial
#excelvbatutorial
#subprocedure
#vbasubprocedure
#excelvbasubprocedure
#arraylist
#vbaarraylist
#array
#arrays
#dynamic
#dynamicarray
#excelvbaarraylist
#arraylistinvba
#collection
#collections
#vbacollections
#vbatutorial
#clear
#contains
#indexof
#mscorlib
#library
#dll
#tlb
#runtime
#multilanguagestandardcommonobjectruntimelibrary
#microsoftcommonobjectruntimelibrary