EXCEL中根据给定的范围,自动生成一组10个乘除法的算术题
发布网友
发布时间:2022-04-28 16:13
我来回答
共1个回答
热心网友
时间:2022-06-19 15:53
'用VBA编程,以前做过,下面是给你找到的,参考
Sub 乘除法_出题()
'
' 出题_加减法 Macro
' 贾安合 记录的宏 2004-3-30
'
'
MaxLines = 200 '本程序能处理的最大行数
MaxTopics = 10 '本次出题的题目数
MaxData = 99 '最大数字
Sheets("参数").Select
Range("C7").Select
MTi = Round(Val(ActiveCell.FormulaR1C1), 0)
If MTi > 0 Then
MaxTopics = MTi
End If
If MaxTopics > MaxLines Then
MaxTopics = MaxLines
End If
Range("C8").Select
MTi = Round(Val(ActiveCell.FormulaR1C1), 0)
If MTi > 0 Then
MaxData = MTi
End If
Range("C21").Select
MTi = Round(Val(ActiveCell.FormulaR1C1), 0)
If MTi <= 0 Or MTi >= 100 Then
MTi = 13
End If
For i = 1 To MTi
Ri = Round(Rnd() * 100)
Next
ActiveCell.FormulaR1C1 = Ri
Sheets("乘除法").Select
Range("F1").Select
ActiveCell.FormulaR1C1 = "答 题"
Range("G1").Select
ActiveCell.FormulaR1C1 = ""
Range("H1").Select
ActiveCell.FormulaR1C1 = ""
'清除所有数据
LocID = Str(MaxLines + 1)
LocID = Right(LocID, Len(LocID) - 1)
Range("A2:H" + LocID).Select
Selection.ClearContents
For LineNumb = 1 To MaxTopics
LocID = Str(LineNumb + 1)
LocID = Right(LocID, Len(LocID) - 1)
D1 = Round(Rnd() * MaxData, 0)
D2 = Round(Rnd() * MaxData, 0)
If D1 <= 0 Then D1 = 1
If D2 <= 0 Then D2 = 1
'行号
Range("A" + LocID).Select
S = Str(LineNumb)
S = "(" + Right(S, Len(S) - 1) + ")"
ActiveCell.FormulaR1C1 = S
'运算符
Opr = Round(Rnd(), 0)
If Opr = 1 Then
Ro = "×"
R1 = D1
Else
Ro = "÷"
R1 = D1 * D2
End If
'第一个数字
Range("B" + LocID).Select
ActiveCell.FormulaR1C1 = R1
'运算符
Range("C" + LocID).Select
ActiveCell.FormulaR1C1 = Ro
'第二个数字
Range("D" + LocID).Select
Ri = Round(Rnd() * NextMaxData, 0)
ActiveCell.FormulaR1C1 = D2
Range("E" + LocID).Select
ActiveCell.FormulaR1C1 = "="
Next
Range("F2").Select
End Sub
Sub 乘除法_答案()
'
' 答案_乘除法 Macro
' 贾安合 记录的宏 2004-3-30
'
'
MaxLines = 200 '本程序能处理的最大行数
MaxTopics = 10 '本次出题的题目数
MaxData = 99 '最大数字
Sheets("参数").Select
Range("C7").Select
MTi = Round(Val(ActiveCell.FormulaR1C1), 0)
If MTi > 0 Then
MaxTopics = MTi
End If
If MaxTopics > MaxLines Then
MaxTopics = MaxLines
End If
Range("C8").Select
MTi = Round(Val(ActiveCell.FormulaR1C1), 0)
If MTi > 0 Then
MaxData = MTi
End If
Sheets("乘除法").Select
Range("G1").Select
ActiveCell.FormulaR1C1 = "评 阅"
Range("H1").Select
ActiveCell.FormulaR1C1 = "答 案"
For LineNumb = 1 To MaxTopics
LocID = Str(LineNumb + 1)
LocID = Right(LocID, Len(LocID) - 1)
'数字
Range("B" + LocID).Select
D1 = Round(Val(ActiveCell.FormulaR1C1))
Range("D" + LocID).Select
D2 = Round(Val(ActiveCell.FormulaR1C1))
Range("F" + LocID).Select
D3 = Round(Val(ActiveCell.FormulaR1C1))
'运算符
Range("C" + LocID).Select
SOpr = ActiveCell.FormulaR1C1
Err = False
If SOpr = "×" Then
D4 = D1 * D2
Else
If SOpr = "÷" Then
D4 = D1 / D2
Else
Err = True
End If
End If
If Not Err Then
Range("G" + LocID).Select
If D3 = D4 Then
ActiveCell.FormulaR1C1 = "√"
Else
ActiveCell.FormulaR1C1 = "×"
End If
Range("H" + LocID).Select
ActiveCell.FormulaR1C1 = D4
End If
Next
Range("F2").Select
End Sub