Random Sampling 10% of Data

geralde

New Member
Joined
Mar 31, 2003
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Hi All

I have a 290,000 rows of data and I want to randomly pick a sample of 10% of that data.

Can you please help me with a formula to do this?

Thanks

Gerald
 
VBA solution as well:

VBA Code:
Sub jec()
 sp = Range("A2", Range("A" & Rows.Count).End(xlUp))
 sp2 = Application.RandArray(UBound(sp), 1)
 ReDim ar(1 To UBound(sp), 1 To 2)
 
 For j = 1 To (UBound(sp) * 0.1)
    ar(j, 1) = sp(Application.Match(Application.Large(sp2, j), sp2, 0), 1)
    ar(j, 2) = j
 Next

 Range("A2", Range("A" & Rows.Count).End(xlUp)).Offset(, 1).Resize(10) = ar
End Sub
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
VBA solution as well:

VBA Code:
Sub jec()
 sp = Range("A2", Range("A" & Rows.Count).End(xlUp))
 sp2 = Application.RandArray(UBound(sp), 1)
 ReDim ar(1 To UBound(sp), 1 To 2)
 
 For j = 1 To (UBound(sp) * 0.1)
    ar(j, 1) = sp(Application.Match(Application.Large(sp2, j), sp2, 0), 1)
    ar(j, 2) = j
 Next

 Range("A2", Range("A" & Rows.Count).End(xlUp)).Offset(, 1).Resize(10) = ar
End Sub
thank you so much. My VBA is truly awful henxe the reason I stick to excel
 
Upvote 0
But, if you use the formula version, you should set your calculation settings to manual. Otherwise the formula is recalculating every time you make a change in your worksheet.
 
Upvote 0
Or just copy/paste values to another part of the sheet. ;)
 
Upvote 0
But, if you use the formula version, you should set your calculation settings to manual. Otherwise the formula is recalculating every time you make a change in your worksheet.
thank you much for this
 
Upvote 0

Forum statistics

Threads
1,215,671
Messages
6,126,131
Members
449,293
Latest member
yallaire64

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