Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Can I random sample from a set until every sample is selected?

does any know if sampling from a set can be done until all values are selected?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 119
Default Can I random sample from a set until every sample is selected?

random wrote on Sun, 25 Apr 2010 13:37:01 -0700:

does any know if sampling from a set can be done until all
values are selected?

One way would be to have a helper column, put randbetween(1, #values) in
it, replace the random numbers with values (paste special), sort and
then use the rest of the values sequentially.

--

James Silverton
Potomac, Maryland

Email, with obvious alterations: not.jim.silverton.at.verizon.not

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Can I random sample from a set until every sample is selected?

Certainly:

Sub SelectAllRandomly()
'first row with data to choose from
Const FirstRow = 1
'last row with data to choose from
Const LastRow = 100
'column the data to choose from is in
Const sourceColumn = "B"
'column to put random list into
Const newColumn = "D"
Dim destList As Range
Dim anyDestEntry As Range
Dim newFind As Variant
Dim lookAtRow As Long
Dim goFlag As Boolean
Dim foundFlag As Boolean
Dim movedCount As Long

Do While movedCount < (LastRow - FirstRow + 1)
lookAtRow = Int((LastRow - FirstRow + 1) * Rnd + FirstRow)
newFind = Range(sourceColumn & lookAtRow).Value
'for first time thru the loop
If Not goFlag Then
Range(newColumn & FirstRow) = newFind
movedCount = 1
goFlag = True
Else
Set destList = Range(newColumn & FirstRow & ":" _
& Range(newColumn & Rows.Count).End(xlUp).Address)
'is the item already in the list
foundFlag = False
For Each anyDestEntry In destList
If anyDestEntry = newFind Then
foundFlag = True ' already in list
Exit For
End If
Next
If Not foundFlag Then
Range(newColumn & destList.Rows.Count + 1) = newFind
movedCount = movedCount + 1
End If
End If
Loop
End Sub

Assumes that you'll build the new list on same sheet with the full set list.
To put the routine into your workbook:
First, work with a copy of the workbook just in case!
With the copy open, press [Alt]+[F11] to open the VB Editor and choose
Insert -- Module and copy the code above and paste it into the module.
Change the values for:
Const FirstRow = 1
Const LastRow = 100
Const sourceColumn = "B"
Const newColumn = "D"
as needed for your worksheet setup. Save the workbook.
Run the macro.

"random sampling" wrote:

does any know if sampling from a set can be done until all values are selected?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 905
Default Can I random sample from a set until every sample is selected?

"James Silverton" wrote:
have a helper column, put randbetween(1, #values) in it


Using RANDBETWEEN incurs a lot of unnecessary overhead and the risk of a
#NAME error and confusion if the user is not familiar with the ATP (before
Excel 2007).

It is sufficient to fill the column with =RAND().

(I am also bothered by the likelihood of duplicate results from RANDBETWEEN
due to quantization. But I can say with impunity that that is a real
problem.)


----- original message -----

"James Silverton" wrote in message
...
random wrote on Sun, 25 Apr 2010 13:37:01 -0700:

does any know if sampling from a set can be done until all
values are selected?

One way would be to have a helper column, put randbetween(1, #values) in
it, replace the random numbers with values (paste special), sort and then
use the rest of the values sequentially.

--

James Silverton
Potomac, Maryland

Email, with obvious alterations: not.jim.silverton.at.verizon.not


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 119
Default Can I random sample from a set until every sample is selected?

Joe wrote on Sun, 25 Apr 2010 14:46:04 -0700:

"James Silverton" wrote:
have a helper column, put randbetween(1, #values) in it


Using RANDBETWEEN incurs a lot of unnecessary overhead and the
risk of a #NAME error and confusion if the user is not
familiar with the ATP (before Excel 2007).


It is sufficient to fill the column with =RAND().


(I am also bothered by the likelihood of duplicate results
from RANDBETWEEN due to quantization. But I can say with
impunity that is a real problem.)


After I posted, I did realize that RAND would be sufficient but surely
anyone who wants to do random selection will have installed the ATP.
Duplicate values (and these can occur even with RAND) do not cause a
problem since all rows will be represented and Sort does not care about
it.


Email, with obvious alterations: not.jim.silverton.at.verizon.not



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 905
Default Can I random sample from a set until every sample is selected?

Material typo....

I wrote:
I am also bothered by the likelihood of duplicate results from RANDBETWEEN
due to quantization. But I can say with impunity that that is a real
problem.


I meant to write: "I can__not__ say with impunity ...". Klunk!


----- original message -----

"Joe User" <joeu2004 wrote in message
...
"James Silverton" wrote:
have a helper column, put randbetween(1, #values) in it


Using RANDBETWEEN incurs a lot of unnecessary overhead and the risk of a
#NAME error and confusion if the user is not familiar with the ATP (before
Excel 2007).

It is sufficient to fill the column with =RAND().

(I am also bothered by the likelihood of duplicate results from
RANDBETWEEN due to quantization. But I can say with impunity that that is
a real problem.)


----- original message -----

"James Silverton" wrote in message
...
random wrote on Sun, 25 Apr 2010 13:37:01 -0700:

does any know if sampling from a set can be done until all
values are selected?

One way would be to have a helper column, put randbetween(1, #values) in
it, replace the random numbers with values (paste special), sort and then
use the rest of the values sequentially.

--

James Silverton
Potomac, Maryland

Email, with obvious alterations: not.jim.silverton.at.verizon.not



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 119
Default Can I random sample from a set until every sample is selected?

Joe wrote on Sun, 25 Apr 2010 15:54:56 -0700:

I wrote:
I am also bothered by the likelihood of duplicate results
from RANDBETWEEN due to quantization. But I can say with
impunity that that is a real problem.


I meant to write: "I can__not__ say with impunity ...". Klunk!


----- original message -----


"Joe User" <joeu2004 wrote in message
...
"James Silverton" wrote:
have a helper column, put randbetween(1, #values) in it


Using RANDBETWEEN incurs a lot of unnecessary overhead and
the risk of a #NAME error and confusion if the user is not
familiar with the ATP (before Excel 2007).

It is sufficient to fill the column with =RAND().

(I am also bothered by the likelihood of duplicate results
from RANDBETWEEN due to quantization. But I can say with
impunity that that is a real problem.)

----- original message -----

"James Silverton" wrote in
message ...
random wrote on Sun, 25 Apr 2010 13:37:01 -0700:

does any know if sampling from a set can be done until all
values are selected?
One way would be to have a helper column, put randbetween(1,
#values) in it, replace the random numbers with values
(paste special), sort and then use the rest of the values
sequentially.


With reference to randomizing the rows of a data set, which is
essentially what I suggested, it might be useful to include another
helper column with integers 1,2,3.....before the random column. so that
you can get the original order back again.

--

James Silverton
Potomac, Maryland

Email, with obvious alterations: not.jim.silverton.at.verizon.not

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Sample Funkyfido Excel Worksheet Functions 2 September 22nd 08 11:09 AM
How do I make a random sample? Confused student Excel Discussion (Misc queries) 4 April 25th 08 04:12 PM
Select a random sample IPMS Excel Discussion (Misc queries) 2 January 7th 07 02:54 AM
random sample skimpw Excel Worksheet Functions 0 August 15th 06 01:15 AM
Random Sample Without Duplication beccadawn0622 Excel Discussion (Misc queries) 3 January 25th 06 02:13 PM


All times are GMT +1. The time now is 10:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"