EXCEL通过VBA生成小学生混合加减法数学题
孩子荣升小学,数学题目也学习到20以内混合加减法,为了孩子能熟练掌握数学基础运算,给孩子每日练习100道算数题目。
网上有用 randbetween 函数来实现的,如下面的链接内的方法:
https://jingyan.baidu.com/article/f3ad7d0f5178bf09c3345b32.html
这个方法在OFFICE中好像有点问题,按F9无法刷新随机数据。因此为了更友好(家人对ECXEL并不熟悉)的实现功能,采用VBA的方式来实现。最终效果如下图所示。
实现算法也比较简单,见VBA代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
Dim MinNum As Integer Dim MaxNum As Integer Dim SubNum As Integer Sub a() Dim Num1 As Integer Dim Num2 As Integer Dim Num3 As Integer Dim ADorSB1 As Integer Dim ADorSB2 As Integer Dim TSubNum1 As Integer Dim TSubNum2 As Integer Dim te As Integer MinNum = Cells(30, 3).Value MaxNum = Cells(30, 6).Value + 1 SubNum = Cells(30, 9).Value For i = 1 To 100 te = Fix((i - 1) / 25) For j = 1 To 100 Num1 = suiji Num2 = suiji Num3 = suiji ADorSB1 = suijiADorSB ADorSB2 = suijiADorSB If ADorSB1 Then TSubNum1 = Num1 + Num2 Else TSubNum1 = Num1 - Num2 End If If ADorSB2 Then TSubNum2 = TSubNum1 + Num3 Else TSubNum2 = TSubNum1 - Num3 End If If TSubNum1 >= 0 And TSubNum2 >= 0 And TSubNum1 <= SubNum And TSubNum2 <= SubNum Then If ((ADorSB1 = 0 And Num2 >= 10) Or (ADorSB2 = 0 And Num3 >= 10)) Then Else Cells((i + 1) - (te * 25), te * 3 + 2).Value = Num1 & IIf(ADorSB1, "+", "-") & Num2 & IIf(ADorSB2, "+", "-") & Num3 & "=" Exit For End If End If Next j Next i Cells(30, 11).Value = Now End Sub '获取随机数 Function suiji() As Integer Randomize suiji = Int(MinNum + Rnd * (MaxNum - MinNum)) End Function '获取随机加减号 Function suijiADorSB() As Integer Randomize suijiADorSB = Int(Round(Rnd, 0)) End Function |
有公众号之类的吗,之前这个网站打不开了
[…] 关于使用Change…
[…] 关于使用Functi…
谢谢提醒,已删 :)
还有你上边文章的图片里有一个账户名没有打…