小学生Excel做题vba代码

Sub msgbox_question()

Dim a, b, i, j, k, answer, correct_answer, erro_answer As Integer

Dim start_time, end_time

Dim cr As Integer '第一行空行的行标

With Sheets("Sheet1")

On Error Resume Next

a = Sheet1.UsedRange.Rows.Count '数行数,当前单元格

MsgBox (Chr(9) & "本次测试共有" & (a - 1) * 3 & "个题目," _

       & Chr(10) _

       & Chr(10) _

       & Chr(9) & "下面,开始做题了")

       start_time = Now()

correct_answer = 0

erro_answer = 0

For i = 2 To a

   answer = Int(InputBox(Range("b" & i), "请输入答案" & i - 1 & "/" & (a - 1) * 3))  '需要最后规范为整形变量

       If answer = Range("c" & i).Value Then

           correct_answer = correct_answer + 1

       Else

           MsgBox ("错误,正确答案是:" _

           & Chr(10) _

           & Chr(9) & Range("c" & i))

           erro_answer = erro_answer + 1

           With Sheets("错题记录")

           cr = .[a65536].End(xlUp).Row + 1

           .Cells(cr, 1) = Range("b" & i)

           End With

       End If

Next

For j = 2 To a

   answer = Int(InputBox(Range("d" & j), "请输入答案" & i + j - 3 & "/" & (a - 1) * 3)) '需要最后规范为整形变量

       If answer = Range("e" & j).Value Then

           correct_answer = correct_answer + 1

       Else

           MsgBox ("错误,正确答案是:" _

           & Chr(10) _

           & Chr(9) & Range("e" & j))

           erro_answer = erro_answer + 1

            With Sheets("错题记录")

           cr = .[a65536].End(xlUp).Row + 1

           .Cells(cr, 1) = Range("d" & j)

           End With

       End If

Next

For k = 2 To a

   answer = Int(InputBox(Range("f" & k), "请输入答案" & i + j + k - 5 & "/" & (a - 1) * 3)) '需要最后规范为整形变量

       If answer = Range("g" & k).Value Then

           correct_answer = correct_answer + 1

       Else

           MsgBox ("错误,正确答案是:" _

           & Chr(10) _

           & Chr(9) & Range("g" & k))

           erro_answer = erro_answer + 1

           With Sheets("错题记录")

           cr = .[a65536].End(xlUp).Row + 1

           .Cells(cr, 1) = Range("f" & k)

           End With

       End If

Next

       end_time = Now()

MsgBox ("答题结束,一共回答" & correct_answer + erro_answer & "道题" _

       & Chr(10) _

       & "回答正确" & correct_answer & "道题" _

       & Chr(10) _

       & "回答错误" & erro_answer & "道题" _

       & Chr(10) _

       & "正确率为" & Round(correct_answer * 100 / (correct_answer + erro_answer), 2) & "%" _

       & Chr(10) _

       & "用时" & Second(end_time - start_time) & "秒")

End With

End Sub

你可能感兴趣的:(小学生Excel做题vba代码)