Hello,
I'm trying to create a database of trivia questions for work. The questions will be in one column, the answers will be in another, and a third column will contain category tags (Sports, Movies, etc.) The goal is for our trivia host to be able to open up this file, filter down to one category, and then have it randomly select 20 questions from that category. Obviously we don't want any duplicates in those 20 questions.
I found a code (below) that does reorganize a column into a random order without repeating, but it does not update if I filter down the list. It still pulls from the full, unfiltered list in the column.
Granted, this code pulls the full list. So if there's 300 questions, it will just randomly reorder all 300. That would still be fine, as I could then just take the first 20, but if there was a way to limit it to only selecting 20, that would be great.I'm not sure if that code can be easily manipulated to perform what I am going for, but if it can, or if anyone has any other ideas on how to complete this task, all help would be greatly appreciated.
Thank you!
I'm trying to create a database of trivia questions for work. The questions will be in one column, the answers will be in another, and a third column will contain category tags (Sports, Movies, etc.) The goal is for our trivia host to be able to open up this file, filter down to one category, and then have it randomly select 20 questions from that category. Obviously we don't want any duplicates in those 20 questions.
I found a code (below) that does reorganize a column into a random order without repeating, but it does not update if I filter down the list. It still pulls from the full, unfiltered list in the column.
Code:
Sub randomCollection()
Dim Names As New Collection
Dim lastRow As Long, i As Long, j As Long, lin As Long
Dim wk As Worksheet
Set wk = Sheets("Sheet1")
With wk
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For i = 2 To lastRow
Names.Add wk.Cells(i, 1).Value, CStr(wk.Cells(i, 1).Value)
Next i
lin = 1
For i = lastRow - 1 To 1 Step -1
j = Application.WorksheetFunction.RandBetween(1, i)
lin = lin + 1
Range("B" & lin) = Names(j)
Names.Remove j
Next i
End Sub
Granted, this code pulls the full list. So if there's 300 questions, it will just randomly reorder all 300. That would still be fine, as I could then just take the first 20, but if there was a way to limit it to only selecting 20, that would be great.I'm not sure if that code can be easily manipulated to perform what I am going for, but if it can, or if anyone has any other ideas on how to complete this task, all help would be greatly appreciated.
Thank you!