Returning only visible data for RANDARRAY

baileyb103

New Member
Joined
Jan 16, 2023
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi. I am creating a question bank for a module that is made up of multiple class studies. I have created the full question bank and I am using RANDARRAY function to return a random test paper. Initially I just wanted to create an end of module test but now I've been asked if I can use the bank to create random tests for each class study. I have attempted this by adding in a column with the class study number for each question and filtering, but the RANDARRAY returns results from all the data not just the visible data. Is there anything I can add to the formula or do to the sheet to only return data from the visible cells? The current formula looks like this... =INDEX(SORTBY(C2:F118,RANDARRAY(ROWS(C2:F118))),SEQUENCE(H1),{1,2,3,4})
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Personally I would add a helper column to the question bank using the formula
Excel Formula:
=SUBTOTAL(3,C2)
filled down to the end, then use that as the first array in SORTBY.

Note that the SUBTOTAL formula needs to look at a column that will have data in all visible rows, formula blanks are ok but empty cells will mess up the sort order.

Assuming the helper formula in G2:G118 you would then change your formula to
Excel Formula:
=INDEX(SORTBY(C2:G118,G2:G118,-1,RANDARRAY(ROWS(C2:F118))),SEQUENCE(H1),{1,2,3,4})

I haven't got anything to hand that is suitable to test this on but I believe that it will work as required.
 
Upvote 0
Thank you Jason. I've tried that but there is an error box comes up saying I've entered too few arguments for this function.
 
Upvote 0
Sorry, I forgot to include the sort order for the second array in SORTBY.
Excel Formula:
=INDEX(SORTBY(C2:G118,G2:G118,-1,RANDARRAY(ROWS(C2:F118)),1),SEQUENCE(H1),{1,2,3,4})
 
Upvote 0
Another option, still using the helper column in G is
Excel Formula:
=LET(f,FILTER(C2:F118,G2:G118=1),TAKE(SORTBY(f,RANDARRAY(ROWS(f))),H1))
 
Upvote 0
Solution
Sorry, I forgot to include the sort order for the second array in SORTBY.
Excel Formula:
=INDEX(SORTBY(C2:G118,G2:G118,-1,RANDARRAY(ROWS(C2:F118)),1),SEQUENCE(H1),{1,2,3,4})
That now works perfectly thank you.
 
Upvote 0
Another option, still using the helper column in G is
Excel Formula:
=LET(f,FILTER(C2:F118,G2:G118=1),TAKE(SORTBY(f,RANDARRAY(ROWS(f))),H1))
Unfortunately this didn't work. The one that Jason put in now does so just going to go with that, but thank you anyway.
 
Upvote 0
@Fluffs formula should give the desired output, it might be that you don't have the update with the TAKE function yet.
 
Upvote 0
Good afternoon, I thought this had worked but it doesn't seem to be now. I have made the spreadsheet so I can share it (ie no sensitive questions). When I filter the columns for say user group 1, the test paper on the other tab still shows questions from the unfiltered list.
 

Attachments

  • Capture.PNG
    Capture.PNG
    116.6 KB · Views: 16
  • Capture1.PNG
    Capture1.PNG
    65.3 KB · Views: 20
Upvote 0
In what way didn't the formula I suggested work?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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