random selection from a specific worksheet to show in a specific cell in another worksheet

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
161
Office Version
  1. 2016
Platform
  1. Windows
Hi

As the title states, I am seeking to have a command button on sheet "Home Page". When selected, a random selection would happen on sheet "Audit-Staffing" in column F. The result would populate in cell B2 on sheet "Monitoring".

another twist is that in column AO of sheet "Audit-Staffing" in each row there is a value of True or False. True value would mean that this file has already been audited so that selection should no longer be an option.

Can someone provide me with assistance?

much appreciated;

thank you
Dan
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Rather than using VBA, you could use a formula to get the random name you seek. Try the following to see if it gives you what you want. Instead of a command button/macro, simply press the F9 key when on the Monitoring sheet to recalculate. I've assumed that column AO of the Audit-Staffing sheet is a genuine TRUE or FALSE value & not a text string "TRUE' or "FALSE". Adjust the bottom row in the formula (currently 29) to whatever you need for your list of names.

RANDOM AUDIT.xlsx
FANAO
1Staff memberT/F
2AdamTRUE
3BrendaTRUE
4CharlesFALSE
5DorisTRUE
6EricTRUE
7FridaTRUE
8GeorgeTRUE
9HarrietTRUE
10IvanFALSE
11JoanTRUE
12KenTRUE
13LouiseTRUE
14MarkFALSE
15NoraFALSE
16OliverFALSE
17PetaFALSE
18QuintenFALSE
19RuthFALSE
20StanTRUE
21TheresaTRUE
22UsmanTRUE
23VeraFALSE
24WillFALSE
25XenaTRUE
26YorichTRUE
27ZaraTRUE
Audit-Staffing


RANDOM AUDIT.xlsx
AB
1
2Here:Quinten
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F29,LARGE(IF('Audit-Staffing'!AO2:AO29=FALSE,ROW('Audit-Staffing'!AO2:AO29)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO29,FALSE)+1)))
 
Upvote 0
Rather than using VBA, you could use a formula to get the random name you seek. Try the following to see if it gives you what you want. Instead of a command button/macro, simply press the F9 key when on the Monitoring sheet to recalculate. I've assumed that column AO of the Audit-Staffing sheet is a genuine TRUE or FALSE value & not a text string "TRUE' or "FALSE". Adjust the bottom row in the formula (currently 29) to whatever you need for your list of names.

RANDOM AUDIT.xlsx
FANAO
1Staff memberT/F
2AdamTRUE
3BrendaTRUE
4CharlesFALSE
5DorisTRUE
6EricTRUE
7FridaTRUE
8GeorgeTRUE
9HarrietTRUE
10IvanFALSE
11JoanTRUE
12KenTRUE
13LouiseTRUE
14MarkFALSE
15NoraFALSE
16OliverFALSE
17PetaFALSE
18QuintenFALSE
19RuthFALSE
20StanTRUE
21TheresaTRUE
22UsmanTRUE
23VeraFALSE
24WillFALSE
25XenaTRUE
26YorichTRUE
27ZaraTRUE
Audit-Staffing


RANDOM AUDIT.xlsx
AB
1
2Here:Quinten
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F29,LARGE(IF('Audit-Staffing'!AO2:AO29=FALSE,ROW('Audit-Staffing'!AO2:AO29)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO29,FALSE)+1)))
Hi

So the formula did produce a result as soon as I entered the formula in B2 but not sure how the F9 key comes into play because when I press it, nothing happens; it does not recalculate. Also will this always produce the next match in the list? so if the next row has a False in AO, then it will select that one or does it really randomly select a row that has False in column AO. There is no real end to column AO as new entries will continue to be added to the Audit-Staffing sheet
 
Upvote 0
Not sure why the F9 key does not recalculate your sheet for you. When I press it, using the dummy data described in post#2 I get this:
First press:
RANDOM AUDIT.xlsx
AB
2Here:Mark
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F27,LARGE(IF('Audit-Staffing'!AO2:AO27=FALSE,ROW('Audit-Staffing'!AO2:AO27)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO27,FALSE)+1)))

Second press:
RANDOM AUDIT.xlsx
AB
2Here:Vera
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F27,LARGE(IF('Audit-Staffing'!AO2:AO27=FALSE,ROW('Audit-Staffing'!AO2:AO27)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO27,FALSE)+1)))

Third press:
RANDOM AUDIT.xlsx
AB
2Here:Peta
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F27,LARGE(IF('Audit-Staffing'!AO2:AO27=FALSE,ROW('Audit-Staffing'!AO2:AO27)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO27,FALSE)+1)))


So you see that the next selection is not 'in order' but randomly selected from the list. I'm no sure if the solution proposed will work for you though, as the formula only seems to work correctly if the range is exactly matching your data range. A VBA solution (or a better formula) may be the answer. Are you able to provide a sample of your actual data (you can disguise the names - replace them all with ="Name "&Row() ) using the XL2BB add in, or alternatively, share your file via Google Drive, Dropbox or similar file sharing platform?
 
Upvote 0
Not sure why the F9 key does not recalculate your sheet for you. When I press it, using the dummy data described in post#2 I get this:
First press:
RANDOM AUDIT.xlsx
AB
2Here:Mark
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F27,LARGE(IF('Audit-Staffing'!AO2:AO27=FALSE,ROW('Audit-Staffing'!AO2:AO27)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO27,FALSE)+1)))

Second press:
RANDOM AUDIT.xlsx
AB
2Here:Vera
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F27,LARGE(IF('Audit-Staffing'!AO2:AO27=FALSE,ROW('Audit-Staffing'!AO2:AO27)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO27,FALSE)+1)))

Third press:
RANDOM AUDIT.xlsx
AB
2Here:Peta
Monitoring
Cell Formulas
RangeFormula
B2B2=INDEX('Audit-Staffing'!F2:F27,LARGE(IF('Audit-Staffing'!AO2:AO27=FALSE,ROW('Audit-Staffing'!AO2:AO27)-ROW('Audit-Staffing'!AO2)+1),INT(RAND()*COUNTIF('Audit-Staffing'!AO2:AO27,FALSE)+1)))


So you see that the next selection is not 'in order' but randomly selected from the list. I'm no sure if the solution proposed will work for you though, as the formula only seems to work correctly if the range is exactly matching your data range. A VBA solution (or a better formula) may be the answer. Are you able to provide a sample of your actual data (you can disguise the names - replace them all with ="Name "&Row() ) using the XL2BB add in, or alternatively, share your file via Google Drive, Dropbox or similar file sharing platform?
I actually get a #NUM! error.

I don't expect the data to go passed row 2000 so the range could be from F2:F2000 but I can't have a return of a blank cell.

I can ensure that the value in Rows 2 to 2000 is False as a default, but will that possibly return a blank option? Also, the F9 function does not work for me neither.

What I would really like to be able to is have a command button next to each Branch
1694722979650.png

that would activate the random selection for the corresponding Branch sheet (i.e Audit-Staffing) and then one last button at the button that would activate the Monitoring sheet.

on Monitoring sheet, there would be a cell next to each Branch with a populated random selection.
1694723564576.png


I have been doing some searching and it is possible using VBA but unfortunately a lot of the examples I come across are too complex for me to understand in order for me to adapt it to my situation.
 
Upvote 0
Again, could you provide a sample using the XL2BB add in, or share your file via Google Drive, Dropbox or similar file sharing platform? You can't copy from an image.
 
Upvote 0
You have to make the shared file available to anyone with the link...
 
Upvote 0
Thank you, I have it now, and by the looks of it I will be passing on this one. I note your workbook comprises (among other things) around 50+ forms - not my area at all I'm afraid. Hopefully, another volunteer on the forum will be able to rise to the challenge. Good luck & best wishes (y)
 
Upvote 0

Forum statistics

Threads
1,223,931
Messages
6,175,465
Members
452,646
Latest member
tudou

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