doctored examples
Code
- Option Explicit
- Sub ptest()
- 'http://www.robvanderwoude.com/vbstech.php#Data
- 'http://www.thecodecage.com/forumz/showthread.php?p=1055000938#post1055000938
- 'this code creates and populates an ArrayList
- Dim myArrayList As Object, myArrayList2 As Object
- Dim xItem, myrange
- Set myArrayList = CreateObject("System.Collections.ArrayList")
- myArrayList.Add "Kyle"
- myArrayList.Add "123"
- myArrayList.Add "C"
- myArrayList.Add "snb"
- myArrayList.Add "pike"
- 'result to immediate window
- Debug.Print Join(myArrayList.toarray(), Chr(10))
- ' copy / clone ArrayList
- Set myArrayList2 = myArrayList.Clone
- 'Now, to add an element and sort the ArrayList, all we need to do is:
- 'add the new element to the ArrayList
- myArrayList.Add "Z"
- 'remove the new element to the ArrayList
- myArrayList.Remove "C"
- 'result to immediate window
- Debug.Print Join(myArrayList.toarray(), Chr(10))
- 'result to immediate window
- Debug.Print "List Has C " & myArrayList.Contains("C")
- Debug.Print "List Has Z " & myArrayList.Contains("Z")
- 'result to immediate window - count elements and capacity
- Debug.Print "Size : " & myArrayList.Count
- Debug.Print "Capacity : " & myArrayList.Capacity
- 'trim blank elements from the ArrayList
- myArrayList.TrimToSize
- 'result to immediate window - count elements and capacity
- Debug.Print "Size : " & myArrayList.Count
- Debug.Print "Capacity : " & myArrayList.Capacity
- 'sort the ArrayList
- myArrayList.Sort
- 'result to immediate window
- Debug.Print Join(myArrayList.toarray(), Chr(10))
- ' reverse the ArrayList
- myArrayList.Reverse
- 'result to immediate window
- Debug.Print Join(myArrayList.toarray(), Chr(10))
- ' copy / clone ArrayList2 result to immediate window
- Debug.Print Join(myArrayList2.toarray(), Chr(10))
- 'toarray transfer ArrayList to results to worksheet
- Range("B1").Resize(myArrayList.Count) = Application.Transpose(myArrayList.toarray())
- Range("C1").Resize(1, myArrayList.Count) = myArrayList.toarray()
- Set myArrayList = Nothing
- Set myArrayList2 = Nothing
- End Sub
thats cool no loops