data validation from multiple choice questions

tridento

New Member
Joined
Mar 21, 2014
Messages
5
Hi
I'm creating multiple choice test and i have everything done apart from the answer data validation. The problem is the questions are from a question bank of around 40 which 10 are randomly chosen and i cant figure how to create a dynamic data validation.
Main sheet table
questionsanwsersright or wrong
how many grams in a kilogram
Which of these is not a colour

<tbody>
</tbody>
Questions and answers sheet table where answer abolute isn't used for the data validation but for the right wrong check
question numberquestionanswer absolutetrue answerfalseanswer1falseanswer2falseanswer3
1how many grams in a kilogram10001000900500530
2Which of these is not a colourhddhddredyellowpink

<tbody>
</tbody>

Code:
Public Sub commandbutton1_click()
Dim i As Integer, RowNum As Integer, rList As String

'Sheets("Welcome").Visible = False
Sheets("Main").Range("A:D").ClearContents
Sheets("Sheet3").Range("B:B").ClearContents
Sheets("Sheet3").Range("A:A").ClearContents

Random_Question = Sheets("Questions_and_Answers").Range("G2")
Random_Questions = Random_Question + 1
Question_bank = Sheets("Questions_and_Answers").Range("F2")
Question_banks = Question_bank + 1

For i = 2 To Question_banks

generate:
RowNum = Application.RoundUp(Rnd() * Random_Questions, 0)
If RowNum = 1 Then
GoTo generate

ElseIf Application.CountIf(Sheets("Main").[A:A], Sheets("Questions_and_Answers").Cells(RowNum, "B")) = 0 Then

Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Questions_and_Answers").Cells(RowNum, "A").Value ' question numbers


Sheets("Main").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Questions_and_Answers").Cells(RowNum, "B").Value ' questions



Sheets("Main").Range("C" & Rows.Count).End(xlUp).Offset(1).Value = "=IF(B" & i & "=Questions_and_Answers!C" & RowNum & ", ""correct"", ""try again"")" ' result

Sheets("Sheet3").Range("B" & Rows.Count).End(xlUp).Offset(1).Value = "=IF(Main!C" & i & "=""correct"",1,0)" ' result value 1 is correct o is wrong


Else
GoTo generate
End If

Next i

Sheets("Sheet3").Select
Range("A1").Value = "Question Number"
Range("A1").Font.Bold = True
Range("A:A").Columns.AutoFit
Range("B1").Select
Range("B1").Value = "Answers Correct"
Range("B:B").HorizontalAlignment = xlCenter
Range("B:B").Columns.AutoFit


Sheets("Main").Select

Range("A1").Value = "Questions"
Range("A1").Font.Bold = True
Range("A:A").HorizontalAlignment = xlCenter
Range("A:A").Columns.AutoFit

Range("B1").Select
Range("B1").Value = "Answer The Questions"
Range("B1").Font.Bold = True
Range("B:B").HorizontalAlignment = xlCenter
Range("B:B").Columns.AutoFit
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
might have solved this
so after
Code:
Sheets("Main").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Questions_and_Answers").Cells(RowNum, "B").Value ' questions
but before
Code:
Sheets("Main").Range("C" & Rows.Count).End(xlUp).Offset(1).Value = "=IF(B" & i & "=Questions_and_Answers!C" & RowNum & ", ""correct"", ""try again"")" ' result
i added
Code:
Set Rng = Sheets("Main").Range("B" & i)

cellToBeReferred = "Questions_and_Answers!D" & RowNum & ":G" & RowNum & ""


With Rng.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:= _
    "=" & cellToBeReferred & ""
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With
so it loops with the script adding the data validation from the question and answer sheet to the main page rows which change when i value changes also when more questions are added it still works - which is a plus:)
i think i'll have a pint - i just started learning about excel vba a month ago and i'm chuffed i've gotten this far. thanks
 
Upvote 0

Forum statistics

Threads
1,215,398
Messages
6,124,699
Members
449,180
Latest member
craigus51286

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