Vba Code Help

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.

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
So when i add a new question it will go to 5
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,225,137
Messages
6,183,076
Members
453,146
Latest member
Lacey D

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