Excel VBA Random User data select and display

imgaur7

New Member
Joined
Dec 25, 2017
Messages
32
I am working on some excel data where in need to randomly select 5 (or 10) equal number of data from different user and display in a different sheet. As it is big sheet it becomes a time taking process, and for that I am looking to get a VBA which may go ahead and select random data and display.

Eg: (need to randomly select 3 data from each user A0123 and B0123)
[TABLE="width: 323"]
<tbody>[TR]
[TD]User[/TD]
[TD]Data1[/TD]
[TD]Data2[/TD]
[TD]Data3[/TD]
[TD]Data4[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]123501[/TD]
[TD]12457[/TD]
[TD]547896[/TD]
[TD]546231[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]4568453[/TD]
[TD]2156465[/TD]
[TD]5445445[/TD]
[TD]7545565[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]9013405[/TD]
[TD]4300473[/TD]
[TD]10342994[/TD]
[TD]14544899[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]13458357[/TD]
[TD]6444481[/TD]
[TD]15240543[/TD]
[TD]21544233[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]17903309[/TD]
[TD]8588489[/TD]
[TD]20138092[/TD]
[TD]28543567[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]22348261[/TD]
[TD]10732497[/TD]
[TD]25035641[/TD]
[TD]35542901[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]26793213[/TD]
[TD]xbcs[/TD]
[TD]29933190[/TD]
[TD]42542235[/TD]
[/TR]
[TR]
[TD]A0123[/TD]
[TD]31238165[/TD]
[TD]15020513[/TD]
[TD]34830739[/TD]
[TD]49541569[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]35683117[/TD]
[TD]17164521[/TD]
[TD]39728288[/TD]
[TD]56540903[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]40128069[/TD]
[TD]19308529[/TD]
[TD]ytytt[/TD]
[TD]63540237[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]44573021[/TD]
[TD]fhghg[/TD]
[TD]49523386[/TD]
[TD]70539571[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]49017973[/TD]
[TD]23596545[/TD]
[TD]54420935[/TD]
[TD]77538905[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]53462925[/TD]
[TD]25740553[/TD]
[TD]59318484[/TD]
[TD]fgfgfg[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]sadsd[/TD]
[TD]27884561[/TD]
[TD]64216033[/TD]
[TD]91537573[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]62352829[/TD]
[TD]30028569[/TD]
[TD]69113582[/TD]
[TD]98536907[/TD]
[/TR]
[TR]
[TD]B0123[/TD]
[TD]66797781[/TD]
[TD]32172577[/TD]
[TD]74011131[/TD]
[TD]105536241[/TD]
[/TR]
</tbody>[/TABLE]

Kindly suggest as how to go ahead with it. Thanks to all in advance.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
If the table is in A1 then to randomly choose data for A0123 then for example...

Code:
Dim rng As Range
Dim randomRow As Long, randomColumn As Long

Randomize
randomRow = CLng((8 - 2 + 1) * Rnd + 2)

Randomize
randomColumn = CLng((5 - 2 + 1) * Rnd + 2)

Set rng = Cells(randomRow, randomColumn)
https://www.techonthenet.com/excel/formulas/rnd.php (use Long for row numbers)

that would choose a random cell from rows 2-8 and columns B-E

do that 5, 10, 3 times... not sure, your explanation wasn't really clear

you can use collections to keep track of selections and to retry if you get repeats, unless repeats dont matter. Also you can search first to see what rows A0123 is on if it can be different. There are functions to find text and then get the row from the range or use a loop and check each cell yourself.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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