Multiple choice question generator using randomly selected Excel ranges

MarkSELA

New Member
Joined
Dec 27, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
  1. I downloaded and installed xl2bb but my Windows 11 system is refusing to unblock it. I've tried unblocking it through system settings but no success. I've tried placing the add-in in a trusted folder and still not working.
  2. I am designing a worksheet which will generate a random selection of math concept multiple choice questions. I am using
    Excel Formula:
    =INDEX(SORTBY(D2:D7,RANDARRAY(ROWS(D2:D7))),SEQUENCE(4),{1})
    to jumble correct answers and wrong answers for each question. Wrong answers shaded in green and correct answers shaded in yellow.
  3. Each question (bordered in red for the purpose of this request) is a named range: Question_1, Question_2, etc.
  4. I want to paste a random selection of these ranges elsewhere in this same sheet. The blue shaded section is my feeble attempt to do that. I'm getting text strings and not ranges. Each question requires 8 rows on its own.
  5. The final product after copying and pasting to document (Word then PDF) will look like this.
  6. I know some VBA, which I've tried. As I've progressed through this project I've moved away from VBA relying more on Excel's built=in functions to do the work.

MC Question Generator.xlsm
ABCDEFGHIJK
1
2 The sum of two odd integers is always odd.may be odd.Question_1 Question_4A random selection of 5 questions from the 9 which exist.
3   may be odd.may be odd or even.Question_2Question_9
4a.may be odd. can always be divided by 3.is always odd.Question_3Question_7
5b.can always be divided by another odd integer. can always be divided by another odd integer.can always be divided by another odd integer.Question_4Question_2
6c.may be odd or even. may be odd or even.is always even.Question_5Question_8
7d.is always odd. is irrational.Question_6
8e.is always even.Eis always even.Question_7
9  can be divided by 2.Question_8
10is never odd.Question_9
11
12 The sum of two even integers is always odd.can always be divided by odd integer.
13   may be odd.may be odd or even.
14a.can always be divided by odd integer. can always be divided by 3.can always be divided by 3.
15b.can always be divided by 3. can always be divided by odd integer.may be odd.
16c.may be odd or even. may be odd or even.can be divided by 2.
17d.may be odd. is irrational.
18e.can be divided by 2.Eis always even.
19   can be divided by 2.
20is never odd.
21
Sheet1
Cell Formulas
RangeFormula
E2:E5,E12:E15E2=INDEX(SORTBY(D2:D7,RANDARRAY(ROWS(D2:D7))),SEQUENCE(4),{1})
I2,A19:B19,C12:C13,B13,A12:A13,A9:B9,C2:C3,B3,A2:A3I2=""
J2:J6J2=INDEX(SORTBY(H2:H10,RANDARRAY(ROWS(H2:H10))),SEQUENCE(5),{1})
B4:B8,B14:B18B4=INDEX(SORTBY(E2:E6,RANDARRAY(ROWS(E2:E6))),SEQUENCE(5),{1})
E6,E16E6=INDEX(SORTBY(D8:D10,RANDARRAY(ROWS(D8:D10))),SEQUENCE(1),{1})
C4,C14C4=IF(B4=D$8,"A",IF(B4=D$9, "A",IF(B4=D$10, "A","")))
C5,C15C5=IF(B5=D$8,"B",IF(B5=D$9, "B",IF(B5=D$10, "B","")))
C6,C16C6=IF(B6=D$8,"C",IF(B6=D$9, "C",IF(B6=D$10, "C","")))
C7,C17C7=IF(B7=D$8,"D",IF(B7=D$9, "D",IF(B7=D$10, "D","")))
C8,C18C8=IF(B8=D$8,"E",IF(B8=D$9, "E",IF(B8=D$10, "E","")))
C19C19=IF(B19=D$18,"Answer",IF(B19=D$19, Answer,IF(B19=D$20, "Answer","")))
Dynamic array formulas.


 

Attachments

  • Screenshot 2024-07-21 095834.jpg
    Screenshot 2024-07-21 095834.jpg
    35.9 KB · Views: 10
  • Screenshot 2024-07-21 095834.jpg
    Screenshot 2024-07-21 095834.jpg
    35.9 KB · Views: 10

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I wrote a short Python script which does what I need.


Python:
#Opens the Excel workbook containing the MC questions.

import xlwings as xw
mypath= "C:\\Users\\barry\\Desktop\\WS Generators\\MC Question Generator2.xlsm"
app= xw.App()
wb=app.books.open(mypath)
sheet = wb.sheets["Sheet1"]



import random
randomnumber = random.randint(1,20)
randlist = []
randlist.append(randomnumber)

while len(randlist)<20:
    randomnumber = random.randint(1,20)
    if randomnumber in randlist:
        continue
    else:
        randlist.append(randomnumber)
print(randlist)

for j in range(20):
    question = "Question_"+str(randlist[j])
    print(question)

    sheet.range(question).copy()
    sheet.range((2+8*j,11),(9+8*j,13)).paste(paste="values")
 
Upvote 0
It is not very clear what you have and what you want to accomplish and how we could help.
Could you explain in more detail just focusing on input data and expected result?
 
Upvote 0
It is not very clear what you have and what you want to accomplish and how we could help.
Could you explain in more detail just focusing on input data and expected result?
Sorry for the confusion. I answered my own question from Sunday regarding pasting one cell value into another using xlwings. I should have replied to original post.
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,105
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