Random question (and answer) generator

funtimefrank

New Member
Joined
Dec 5, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm a teacher and want to make my students a random question generator they can use for revision. I intend to create a bank of questions (column A) and answers (column B), and on a different sheet have a button that will display a random question from the question bank. I'd then like an additional button that can be pressed to display the answer. I have done some research and found various ways to use index to display the random questions but not along with the answers. I also don't really understand VBA so can't figure out how to do the buttons. Please help! Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of your sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Here is what I have so far. It is just the main question bank. The idea is to make a separate sheet that would just be a couple of buttons with a display area:
question generator.PNG

Students would press 'New Question' to display a new question (randomly selected from Column A of the question bank sheet); then to check their answer would click 'Answer' to display the corresponding answer.
 
Upvote 0
Click here for your file. Click the buttons on sheet "Question". The following macros are located in Module1:
VBA Code:
Sub SelectRandomQuestion()
    Application.ScreenUpdating = False
    Dim nr As Long
    ActiveSheet.TextBoxes("TextBox 6").Text = ""
    Static AlreadyRandomized As Boolean
    If Not AlreadyRandomized Then
        AlreadyRandomized = True
        Randomize
    End If
    nr = Int(24 * Rnd) + 7
    Sheets("Question").Shapes.Range(Array("TextBox 5")).Select
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = Sheets(1).Range("A" & nr)
    Range("A1").Select
    Application.ScreenUpdating = True
End Sub

Sub GetAnswer()
    Application.ScreenUpdating = False
    Dim fnd As Range
    Set fnd = Sheets(1).Range("A:A").Find(ActiveSheet.TextBoxes("TextBox 5").Text, LookIn:=xlValues, lookat:=xlWhole)
    Sheets("Question").Shapes.Range(Array("TextBox 6")).Select
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = fnd.Offset(, 1)
    Range("A1").Select
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

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