randomly sort my dictionary

Status
Not open for further replies.

asta22

New Member
Joined
Apr 13, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I want to randomly sort my dictionary, here is my code

what should I do ?

MY CODE:

Dim key2 As Variant, ArrayDict As Variant

'create array from dict
k = 1
For Each key2 In dict
ArrayDict(k, 1) = key2
ArrayDict(k, 2) = dict(key2)
k = k + 1
Next key2

' empty the dict
dict.RemoveAll

'randomize array order
For i = 1 To k' mix candidate cities
a1 = random(1, k)
a2 = random(1, k)
a = ArrayDict(a1, 1): ArrayDict(a1, 1) = ArrayDict(a2, 1) : ArrayDict(a2, 1) = a
a = ArrayDict(a1, 2) : ArrayDict(a1, 2) = ArrayDict(a2, 2) : ArrayDict(a2, 2) = a
Next i

'we filled the dict from the array
For i = 1 TB UBound(ArrayDict)
dict(ArrayDict(k, 1)) = ArrayDict(k, 2)
Next i

Thanks in advance
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
i've answered in the "other languages" section
 
Upvote 0
Duplicate to: trier aléatoirement mon dictionnaire

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,216,109
Messages
6,128,880
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top