ArrayList
System.Collections.ArrayList
This does not work with Office 365.
This only works if you have .NET 3.5 installed.
Dim oArrayList As Object
Set oArrayList = CreateObject("System.Collections.ArrayList")
Private Sub SortDictionary(ByVal oDict As Scripting.Dictionary)
On Error Resume Next
Dim oArrayList As Object
Dim oNewDict As Scripting.Dictionary
Dim vKeys As Variant
Dim vKey As Variant
Set oArrayList = CreateObject("System.Collections.ArrayList")
' Transpose Keys into ones based array.
vKeys = oDict.Keys
vKeys = Application.WorksheetFunction.Transpose(vKeys)
For Each vKey In vKeys
Call oArrayList.Add(vKey)
Next
oArrayList.Sort
' Create a new dictionary with the same characteristics as the old dictionary.
Set oNewDict = New Scripting.Dictionary
oNewDict.CompareMode = oDict.CompareMode
' Iterate over the array list and transfer values from old dictionary to new dictionary.
For Each vKey In oArrayList
sKey = CStr(vKey)
If oDict.Exists(sKey) Then
Call oNewDict.Add(sKey, oDict.Item(sKey))
End If
Next
' Replace the old dictionary with new sorted dictionary.
Set oDict = oNewDictionary
Set oNewDict = Nothing
Set oArrayList = Nothing
End Sub
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext