Random Choice

PCRIDE

Well-known Member
Joined
Jan 20, 2008
Messages
907
Hi, I need to build an audit form where 10% of the records need to be flagged for the Audit. I tried using RANDBETWEEN and assigning each record with a random number between 1,10 then choosing 2 or 3 numbers and performing a VLOOKUP but the problem is everytime the sheet is calulated the numbers change.

What would be a recomendation on how to handle this? The flagged Audit records need to remain static as we will append data to this sheet daily, therfore the previous days' records need to remain. Each record also has a unique identifier.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi PCRIDE,

I suggest you use a VBA/macro solution rather than a formula that recalculates. Initially you could use a macro that assigns a static random number to each of your existing records. After this is done I recommend that you implement a Worksheet_Change event that establishes a random number for each new record as it is entered. You wouldn't even have to use a random number generator for this, but could simply use, for example, the fractional seconds portion of the Timer function, which gives the number of seconds elapsed from midnight to the nearest millisecond. Since the record is presumably entered manually, the exact time it is entered is not controllable or repeatable, and is therefore essentially random, and since time progresses uniformly the numbers would be uniformly distributed, just like the RAN function.

Feel free to follow up if you need help with some code.

Damon
 
Upvote 0
one of the trick i am using is for collecting audit sampling is conditional formatting

have look at this


Excel Workbook
A
1177
2193
3187
4148
5149
6196
7113
8149
9181
10190
11130
12158
13101
14155
15135
16136
17105
18147
19117
20190
21156
22113
23102
24126
Sheet3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A11. / Formula is =MOD(ROW(),7)=0Abc
A21. / Formula is =MOD(ROW(),7)=0Abc
A31. / Formula is =MOD(ROW(),7)=0Abc
A41. / Formula is =MOD(ROW(),7)=0Abc
A51. / Formula is =MOD(ROW(),7)=0Abc
A61. / Formula is =MOD(ROW(),7)=0Abc
A71. / Formula is =MOD(ROW(),7)=0Abc
A81. / Formula is =MOD(ROW(),7)=0Abc
A91. / Formula is =MOD(ROW(),7)=0Abc
A101. / Formula is =MOD(ROW(),7)=0Abc
A111. / Formula is =MOD(ROW(),7)=0Abc
A121. / Formula is =MOD(ROW(),7)=0Abc
A131. / Formula is =MOD(ROW(),7)=0Abc
A141. / Formula is =MOD(ROW(),7)=0Abc
A151. / Formula is =MOD(ROW(),7)=0Abc
A161. / Formula is =MOD(ROW(),7)=0Abc
A171. / Formula is =MOD(ROW(),7)=0Abc
A181. / Formula is =MOD(ROW(),7)=0Abc
A191. / Formula is =MOD(ROW(),7)=0Abc
A201. / Formula is =MOD(ROW(),7)=0Abc
A211. / Formula is =MOD(ROW(),7)=0Abc
A221. / Formula is =MOD(ROW(),7)=0Abc
A231. / Formula is =MOD(ROW(),7)=0Abc
A241. / Formula is =MOD(ROW(),7)=0Abc
 
Upvote 0
in the above example i selecting every seventh record
hope this will give you new ideas
 
Upvote 0
Hi, thanks for the responses. I kept searching online and found this code. Works really well!! It will copy the data and paste a % to another sheet.

Can somone help me modify this code to say

If the total count is less than or = to 20 records, copy all the records, otherwise grab 10% of the records.


Option Explicit
Sub Random20()
Randomize 'Initialize Random number seed
Dim MyRows() As Integer ' Declare dynamic array.
Dim numRows, percRows, nxtRow, nxtRnd, chkRnd, copyRow As Integer
'Determine Number of Rows in Sheet1 Column A
numRows = Sheets(4).Range("A" & Rows.Count).End(xlUp).Row
'Get 20% of that number
percRows = numRows * 0.2
'Allocate elements in Array
ReDim MyRows(percRows)
'Create Random numbers and fill array
For nxtRow = 1 To percRows
getNew:
'Generate Random number
nxtRnd = Int((numRows) * Rnd + 1)
'Loop through array, checking for Duplicates
For chkRnd = 1 To nxtRow
'Get new number if Duplicate is found
If MyRows(chkRnd) = nxtRnd Then GoTo getNew
Next
'Add element if Random number is unique
MyRows(nxtRow) = nxtRnd
Next
'Loop through Array, copying rows to Sheet2
For copyRow = 1 To percRows
Sheets(4).Rows(MyRows(copyRow)).EntireRow.Copy _
Destination:=Sheets(5).Cells(copyRow, 1)
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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