Random generator lookup formula

erniepoe

Active Member
Joined
Oct 23, 2006
Messages
380
Office Version
  1. 365
Platform
  1. Windows
Hi all,

So I have a list of program names in column A (many of these programs are listed dozens of times), and I want to randomly choose 7 unique programs at a time, which i do with the below formula pasted into 7 cells in the table I've created.

=INDEX($A:$A,RANDBETWEEN(2,COUNTA($A:$A)),1)


Now, once I've randomly selected a program, I want it to randomly select the "application received date," which it the data in column B. Most programs have many application received dates, and i am hoping to choose three random such dates for each of the random programs chosen from column A. I can't just use the above formula because I need it to be random but be one of the application dates from the random program chosen from column A.


Further, once I've chosen a random application date from the random program, I just want to put in the contact name from that application, which are listed in column C (last name) and column D (first name). So I don't want the names to be random, as a specific name goes along with each application. So once it chooses a random cell in column B for the application date, I just want to grab the corresponding data in columns C and D and paste it in.

Does this make any sense to anybody? Any help is much obliged.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How does your existing formula manage to choose seven unique programs? It could generate duplicates, even if each program is appears only once.

If that somehow happens do what you want, then just use a helper column with the formula =RAND(), sort the whole magilla by that column to put everything in random order, then choose the top 7 lines.
 
Last edited:
Upvote 0
I tried it without using VBA. I suppose it was a bit of an exercise. Ended up being rather elaborate:
Excel Workbook
ABCDEFGHIJK
1***chosenproduct2product3product8product6product3product5product1
2***count614121614118
3***random33841016
4****42116721
5****510123242
6***dates10/14/20092/14/20103/19/20102/27/20121/23/20101/12/201010/10/2009
7****8/18/20122/13/20112/20/20127/14/20117/21/20102/27/201212/11/2010
8****5/10/20091/23/20103/23/20091/19/20092/13/20116/12/20117/10/2011
9***namesname5name3name5name5name3name6name7
10****name5name3name8name5name6name9name3
11****name3name3name7name7name3name4name9
12***surnamessurname5surname1surname2surname3surname8surname7surname7
13****surname8surname4surname4surname4surname7surname6surname6
14productdatenamesurnamesurname7surname8surname8surname7surname4surname8surname7
15product57/18/2012name6surname7*****1*
16product98/22/2009name3surname1*******
17product15/14/2010name3surname6******1
Sheet


Each column represents a chosen product.

The formulas in E3, E6, E9 and E12 have to be copied across the areas with the same colors.
The formula in E15 has to be copied across the row.
The formula in E16 has to be copied across the row, and then across each row that contains a product.

It should be noted that this does not choose unique values, as shg pointed out. You can adjust the way the random values in E3:K5 are generated to change this.
 
Last edited:
Upvote 0
Thanks for the suggestions guys, much appreciated.

So, just for my own edification, would there be a formula or macro that would allow me to pick 7 random and unique names from a column of names?
 
Upvote 0
Did you try this?
just use a helper column with the formula =RAND(), sort the whole magilla by that column to put everything in random order, then choose the top 7 lines.
 
Upvote 0
I did try that, SHG, and thanks. However, I always end up running into the "run time error 91" debugging problem if I record that as a macro and want to refresh multiple times, so it would be nice if there were a random selection formula that could find several unique values.


I guess I can work around it, but was hopeful for a better solution. Cheers!
 
Upvote 0
If you put a workbook on box.net with an example of your data layout and expected result, and then post a link here, I'll look at it.
 
Upvote 0
Out of curiosity, did the excel functions I wrote generate the desired results?
If so, you could apply the same logic with the use of vba.
 
Upvote 0
Thanks moonfish, but your formulas didn't really work. At least, I couldn't get them to work, they just resulted in a lot of #NUM errors. I wasn't quite sure why your formulas kept referring to E5:E113; what's supposed to be there? What do all your asterisks represent?
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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