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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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,798
Messages
6,121,635
Members
449,043
Latest member
farhansadik

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