
We can use the For Each loop with the VBA ArrayList just like we use it with a Collection: ' Print all items to the Immediate Window(Ctrl + G) ' Items much be basic data type e.g. Long, String, Double ' Sub PrintToImmediateWindow(coll As Object)ĭim i As Long For i = 0 To coll.Count - 1 ' Print all items to the Immediate Window(Ctrl + G) ' Items must be basic data type e.g. Note: We will use this PrintToImmediateWindow sub in the follow examples to show the contents of the array after the various operations. We read through the ArrayList similar to the VBA Collection except that we read from zero to Count-1 rather than from one to Count. We use the Add method: ' Sub AddingToList()Ĭoll.Add "Banana" ' Insert to first position It doesn’t matter if you have a later version like 4.7, you must have 3.5 installed.Īdding items to the ArrayList is very similar to how we add them to the Collection. This is caused by not having the correct.
EXCEL FOR MAC 2011 ADODB CODE
Or sometimes your code has been working for a long time and then suddenly this error appears. You may encounter the VB Run-time Error ‘-2146232576 Automation Error’ when trying to get the ArrayList to work. You can now use the following code to declare the ArrayList using early binding: Dim coll As New ArrayList Scroll down the list and check mscorlib.dll.It should be in a folder like this C:\Windows\Microsoft.NET\Framework\v9. Find the file mscorlib.tlb and click Open.Select Tools and then References from the menu.We can use the following steps to do this: We must first add the type library as a reference and then select it from the reference list.
EXCEL FOR MAC 2011 ADODB UPDATE
Update 1: Intellisense doesn’t currently work for the ArrayList.Įarly binding allows use to use the Intellisense to see what is available to use. The advantage is that it is better to use when distributing a VBA application to a user. The disadvantage of late binding is that we don’t have access to the Intellisense. We use CreateObject to create the ArrayList using late binding: ' Sub UsingArrayList()ĭim coll As Object Set coll = CreateObject( "") Like all external libraries we can create the ArrayList using early and late binding. For the purpose of this article, I will refer to it as the VBA ArrayList.

As you would expect, the ArrayList has a built-in sort, array conversion and other functionality that you would expect in a modern programming language. The ArrayList is the same one that is used in the language C#. It is not part of VBA, but it is in an external library which we can access easily. The ArrayList is similar to the VBA built-in Collection. Item - the item to remove from the ArrayListĢ. Set list = CreateObject( "")įind the position of an item in the ArrayList

Sheet1.Range("A3").Resize(list.Count, 1).Value = WorksheetFunction.Transpose(list.ToArray) Sheet1.Range( "A1").Resize(1, list.Count).Value = list.ToArray
