Chose random % of row from sheet1 and paste in to sheet2

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,405
Office Version
  1. 2010
Using Excel 2010

Hello, I have sheet1 with numbers approximately 6000 to 9000 rows with 14 columns I want to pick random % of row and paste in to sheet2.

Please suggest a VBA solution. Thank you in advance.

Example sheet1 with 40 rows
Pick Random Rows.xlsm
ABCDEFGHIJKLMNOPQ
1TT:Rows
240
3
4
5S.Nn1n2n3n4n5n6n7n8n9n10n11n12n13n14
61858577534076247553402365
723972586460694147635265248022
83263014357754682467979664980
942852492837276566431962721342
10521417378109198053368674047
1162419621580481317784152295849
127197144163335303376763103652
1381286264724666267424202747
1491268393133587671397515192332
151048195472432612253651043257
1611155674793245402137024324744
171275481242523251963415171852
181351551123541450192830636256
19141713473176525825744870793755
201580234359937946216861442415
21164338231635286543674169603975
221770373776366246184410582324
2318525645459701204595547112
241952381573658245745332505244
2520545150696115422523737731624
26216514777595927424668503748
27227268577957147525604916336829
28234280237019771026784655234473
29249697435616426237857619937
3025283237523116297815808657311
312655806670645565323503674573
32277852386435619263962594492
3328607017773664777791876677733
342941725971511115350305166457
3530428071391735453754692957256
36313827576763657671155793969
3732634824414523033325136653160
383360803655756814324124784171
39345222762852347359517768513578
40351449535043261328611152746278
4136133675860741816805473633128
42378312478177964806124192478
433820674481762151306673303111
443942391349279566953131426312
454026996816662165662582652
46
47
Sheet1
Cell Formulas
RangeFormula
B2B2=COUNTA(B6:B45)


Random Result selection 10 % of rows = 4 pasted in to sheet2
Pick Random Rows.xlsm
ABCDEFGHIJKLMNOPQ
1TT:Rows
24
3
4
5S.Nn1n2n3n4n5n6n7n8n9n10n11n12n13n14
642852492837276566431962721342
71351551123541450192830636256
8234280237019771026784655234473
9378312478177964806124192478
10
11
12
13
14
Sheet2
Cell Formulas
RangeFormula
B2B2=COUNTA(B6:B45)


Regards,
Moti
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Here i summit the cross post link. Regards, Moti
 
Upvote 0
I read this as you wanting two random numbers - first you want to pick a random number of rows from the total dataset, and then you want to select that number of random rows from the dataset. Is that correct?

VBA Code:
Sub RandomPercent()
    Dim NumSelected As Long, TotalRows As Long, newRnd As Long, i As Long
    Dim inRng, outRng
    TotalRows = Sheets("Sheet1").Range("B2").Value
    inRng = Sheets("Sheet1").Range("B6:P" & TotalRows + 6 - 1)
    Randomize
    NumSelected = Int((TotalRows * Rnd) + 1)
    For i = 1 To NumSelected
        newRnd = Int((TotalRows * Rnd) + 1)
        outRng = Application.WorksheetFunction.Index(Sheets("Sheet1").Range("B6:P" & TotalRows + 6 - 1), newRnd, 0)
        Sheets("Sheet2").Range("B" & i + 5).Resize(1, 15) = outRng
    Next
End Sub
 
Upvote 1
Solution
I read this as you wanting two random numbers - first you want to pick a random number of rows from the total dataset, and then you want to select that number of random rows from the dataset. Is that correct?
Hello myall_blues, I wanted bit specific I can select any amount of % via input any way my request is solved via cross post. I appreciate your help.

Have a good day and Good Luck.

My Best Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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