用法:
打開EXCEL電子表格,,右鍵sheet1------>點“查看代碼”--------->將下面VBA代碼復(fù)制到 book1-sheet1代碼窗口------->按f5功能鍵運行代碼,。即可得到漢語乘法口訣,! Sub 中文乘法口訣()
Dim s$ s = "一二三四五六七八九" Dim x%, y%, n% n = 1 For x = 1 To 9 For y = 1 To n Cells(x, y).Select If x * y < 10 Then Cells(x, y).Value = Mid(s, y, 1) & Mid(s, x, 1) & "得" & Mid(s, x * y, 1) Else If Mid(Format(x * y, "0"), 2, 1) = "0" Then Cells(x, y).Value = Mid(s, y, 1) & Mid(s, x, 1) & Mid(s, x * y / 10, 1) & "十" Else If x * y > 10 And x * y < 20 Then Cells(x, y).Value = Mid(s, y, 1) & Mid(s, x, 1) & "十" & Mid(s, Val(Mid(Format(x * y, "0"), 2, 1)), 1) Else Cells(x, y).Value = Mid(s, y, 1) & Mid(s, x, 1) & Mid(s, Val(Mid(Format(x * y, "0"), 1, 1)), 1) & "十" & Mid(s, Val(Mid(Format(x * y, "0"), 2, 1)), 1) End If End If End If With ActiveCell.Characters(Start:=1, Length:=1).Font .Size = 30 .ColorIndex = 3 End With With ActiveCell.Characters(Start:=2, Length:=1).Font .Size = 30 .ColorIndex = 5 End With With ActiveCell.Characters(Start:=3, Length:=3).Font .Size = 30 .ColorIndex = 1 End With With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = 3 End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = 3 End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = 3 End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = 3 End With Next y n = n + 1 Next x Columns("a:i").ColumnWidth = 27 End Sub |
|