excel VBA 乘法表编写

2025-03-12 23:27:03

1、打开excel表格,再打开VBA编辑界面(All+F11)

excel VBA 乘法表编写

2、点击插入模块

excel VBA 乘法表编写
excel VBA 乘法表编写

3、在模块中输入Sub 乘法表回车,后面的()与End Sub就自动弹出了

excel VBA 乘法表编写

4、输入n1 n2两个从1到9的循环变量Dim n1, n2For n1 = 1 To 9For n2 = 1 To 9Next n2Next n1

excel VBA 乘法表编写

5、再在中间输入条件判断,当n2大于等于n1时,就退出循环,否则就在单元里出现从1到9的乘法表达式倦虺赳式If n2 >= n1 ThenExit ForElseCells(n1, n2) = n2 & "x" & n1 & "=" & n1 * n2End If

excel VBA 乘法表编写

6、写完后按F5,表格里就出现如下乘法表了

excel VBA 乘法表编写

7、如果要从第一个单元格起录入乘法表,就将If n2 > =n1 Then,写成If n2 > n1 Then,去掉=

excel VBA 乘法表编写
excel VBA 乘法表编写

8、如果要从第三行,第三列录入乘法表Cells(n1, n2),写成Cells(n1 + 2, n2 + 2)

excel VBA 乘法表编写
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢