以前学Java,C,C#等高级语言,觉得VBA就是个脚本语言,没啥大用。
随着对VBA的了解的不断深入,越来越觉得自己小看了VBA。今天,就用Excel实现一下任意大小的乘法表的打印吧。
Sub multiplication()
Dim i, j As Integer
Dim size As Integer
size = Application.InputBox(prompt:="请输入乘法表的大小(如,九九乘法表为9)", Title:="打印乘法表", Type:=1)
For i = 1 To size
Cells(6, i + 3) = i
Cells(i + 6, 3) = i
Next i
Rows(6).Font.Bold = True
Rows(6).HorizontalAlignment = xlCenter
Columns(3).Font.Bold = True
Columns(3).HorizontalAlignment = xlCenter
For i = 1 To size
For j = 1 To size
If i <= j Then
Cells(i + 6, j + 3) = i * j
End If
Next j
Next i
End Sub
Sub resetMulitplicationResultArea()
Range("C6").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
Range("C6").Select
End Sub