Random List Of Names rquired

Razor147

New Member
Joined
Mar 27, 2013
Messages
13
I have a list of 147 names in a column and when I run the following VBA code I get another list of 80 random names which is what I want, but I would like the names to change every time I run the macro. At the moment the random names list stays the same. Could anyone please help me. Sub Random_Name()
Dim Rng As Range
Dim Cell As Range
Dim rNum, gName, DupYN
Set Rng = Range("C2:C81")
Rng.ClearContents
For Each Cell In Rng
here:
rNum = Int(146 * Rnd + 1)
gName = Application.VLookup(rNum, Range("A2:B146"), 2, False)
DupYN = Application.WorksheetFunction. _
CountIf(Rng, gName)
If DupYN = 1 Or Cell.Value = gName Then
GoTo here
Else
Cell.Value = gName
End If
Next Cell
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Add "randomize" before line "For Each Cell In Rng"
 
Upvote 0
Or try the following macro:
Code:
Sub Random_Name()
[c2:c146] = [a2:a146].Value
[d2:d146] = "=rand()"
[c2:d146].Sort [d2]
[c82:c146,d2:d146] = ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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