EXCEL VBA - 用VBA寫九九乘法表
以下列出使用EXCEL VBA寫出的九九乘法表。三個範例大同小異,差別只在於99乘法表乘出來的值「對齊的方法不同」。
Chr(10)為換行符號。
範 例 一
Sub 九九乘法表_1()
Dim Table99 As String
For i = 1 To 9
For j = 1 To 9
Table99 = Table99 & i & "X" & j & "=" & i * j & " "
Next
Table99 = Table99 & Chr(10)
Next
Range("C3").FormulaR1C1 = Table99
End Sub
▼範例一 - 結果
範 例 二
Sub 九九乘法表_2()
Dim Table99 As String
For i = 1 To 9
For j = 1 To 9
If (i * j < 10) Then
Table99 = Table99 & i & "X" & j & "=" & i * j & " "
Else
Table99 = Table99 & i & "X" & j & "=" & i * j & " "
End If
Next
Table99 = Table99 & Chr(10)
Next
Range("C4").FormulaR1C1 = Table99
End Sub
▼範例二 - 結果
範 例 三
Sub 九九乘法表_3()
Dim Table99 As String
For i = 1 To 9
For j = 1 To 9
If (i * j < 10) Then
Table99 = Table99 & i & "X" & j & "=" & " " & i * j & " "
Else
Table99 = Table99 & i & "X" & j & "=" & i * j & " "
End If
Next
Table99 = Table99 & Chr(10)
Next
Range("C5").FormulaR1C1 = Table99
End Sub
▼範例三 - 結果
留言列表