OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 833
- Office Version
- 365
- Platform
- Windows
Mr. Excl Lister Rijnsent inspired me to look into dictionaries. I'm part way to use of one the way I need...
I successfuly filled (and tested) a dictionary with numerous label/value pairs. I want to sort the dictionary.
I found a vb function here Sort a dictionary by value to do the sort but, apparently, I was unable to hack it. I declare it thusly
In main function is a dictionary named dicTopHoldings that is filled with those label/value pairs. I want to sort so I call my function like this
dicTopHoldings = SortDictionaryDesc(dicTopHoldings)
I get compile error Argument not optional.
Heheh, for me, argument is to be avoided!
What basic concept am I missing?
TIA a lot.
Jim
I successfuly filled (and tested) a dictionary with numerous label/value pairs. I want to sort the dictionary.
I found a vb function here Sort a dictionary by value to do the sort but, apparently, I was unable to hack it. I declare it thusly
VBA Code:
Private Function SortDictionaryDesc(ByVal dict As Dictionary) As Dictionary
Dim final As New Dictionary
Dim max As Double
Dim prev As Double
Dim key As Variant
Do While dict.Keys.Count - 1 > 0
For Each x In dict.Keys
If dict(x) > max Then
max = dict(x)
key = x
End If
Next
final.Add(key) = max
dict.Remove (key)
max = 0
Loop
SortDictionaryDesc = final
End Function
In main function is a dictionary named dicTopHoldings that is filled with those label/value pairs. I want to sort so I call my function like this
dicTopHoldings = SortDictionaryDesc(dicTopHoldings)
I get compile error Argument not optional.
Heheh, for me, argument is to be avoided!
What basic concept am I missing?
TIA a lot.
Jim