Sebhughes.com
Well-known Member
- Joined
- Oct 11, 2004
- Messages
- 650
I ahve a sheet with question on it for people to answer, for people to answer it they press a button and it picks a random questyion.
Thsi is my code to add a question but i also have this vba to get the random question
I want it so evertime i add a new question Thsi line of code increase
So when i add a new question it will go to 5
Code:
Dim Myvalue As String
Myvalue = InputBox("Please Enter The New Question", "New Question", "New Question")
Value = InputBox("Please Enter The Answer To The Following Question " & vbCr & "'" & Myvalue & "'")
Range("'Questions'!$f$1") = Myvalue
Range("'Questions'!$f$2") = Value
Dim destrangeone As Range
Dim smallrngone As Range
Application.ScreenUpdating = False
For Each smallrngone In Sheets("Questions"). _
Range("f1:f2").Areas
Set destrangeone = Sheets("Questions").Range("A" & _
LastRow(Sheets("Questions")) + 1)
smallrngone.Copy
destrangeone.PasteSpecial xlPasteValues, , False, True
Application.CutCopyMode = False
Next smallrngone
Application.ScreenUpdating = True
Thsi is my code to add a question but i also have this vba to get the random question
Code:
Private Sub CommandButton1_Click()
Const UpperBound As Integer = 4
Const LowerBound As Integer = 3
Dim iRow As Integer
Dim vReply As Variant
Dim WS As Worksheet
Set WS = Sheets("Questions")
CommandButton2.Visible = False
iRow = Int((UpperBound - LowerBound + 1) * Rnd + LowerBound)
If Intersect(Selection, Range("c8:e10")) Is Nothing Then Exit Sub
If Selection.Rows.Count > 1 Then
MsgBox "Please Select 1 Square Only", 0, "Error"
Exit Sub
End If
If Application.CountA(Selection) <> 0 Then
MsgBox "The Square You Have Selected Already Contains A Move", 0, " Error"
Exit Sub
End If
vReply = Application.InputBox(prompt:=WS.Range("A" & iRow).Text & "?")
If LCase$(Trim$((vReply))) = LCase$(Trim$(WS.Range("B" & iRow).Text)) Then
MsgBox ("You Answered Correctly")
ActiveCell.FormulaR1C1 = "X"
CommandButton1.Visible = False
CommandButton2.Visible = True
Else
MsgBox ("Sorry Wrong Answer")
CommandButton1.Visible = False
CommandButton2.Visible = True
End If
Dim sReply As String
sReply = CheckRows
If sReply = "" Then sReply = CheckCols
If sReply = "" Then sReply = CheckDiags
Select Case sReply
Case "X"
[G10] = [c6] & " Wins!"
Range("i11").Value = Range("i11").Value + 1
Range("g8,m8").Value = Range("g8,m8").Value + 1
Range("C8:E10").Select
Selection.ClearContents
Range("C7").Select
Selection.ClearContents
Range("m12").Select
CommandButton1.Visible = True
CommandButton2.Visible = True
Case "O"
[G10] = [E6] & " Wins!"
Range("I8,m9").Value = Range("I8,m9").Value + 1
Range("i11").Value = Range("i11").Value + 1
Range("C8:E10").Select
Selection.ClearContents
Range("C7").Select
Selection.ClearContents
Range("m12").Select
CommandButton1.Visible = True
CommandButton2.Visible = True
Case "*"
[G10] = "Tie!"
Range("H8").Value = Range("H8").Value + 1
Range("i11").Value = Range("i11").Value + 1
Range("C8:E10").Select
Selection.ClearContents
Range("C7").Select
Selection.ClearContents
Range("m12").Select
CommandButton1.Visible = True
CommandButton2.Visible = True
End Select
End Sub
I want it so evertime i add a new question Thsi line of code increase
Code:
Const UpperBound As Integer = 4