標題:
乘法運算?
[打印本頁]
作者:
q1a2z5
時間:
2014-2-19 13:30
標題:
乘法運算?
可否用程式將乘法運算過程解算出來?
謝謝!
作者:
owen06
時間:
2014-2-19 18:14
回復
1#
q1a2z5
這樣可以嗎?
作者:
owen06
時間:
2014-2-19 19:02
回復
2#
owen06
抱歉,上一個檔有寫地方沒寫好,這個你試試看
作者:
stillfish00
時間:
2014-2-19 20:42
回復
1#
q1a2z5
Sub Test()
Dim sA As String, sB As String, sM As String, sRslt As String
Dim rngA, rngRslt As Range
Set rngA = Range("J4:M4") '範圍或位置只要改這裡就好
sA = Join(Application.Transpose(Application.Transpose(rngA.Value)), "")
sB = Join(Application.Transpose(Application.Transpose(rngA.Offset(1).Value)), "")
'清除之前的結果
With rngA
With .Offset(2, -.Count).Resize(.Count + 1, 2 * .Count)
.ClearContents
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
End With
'計算過程
For i = 1 To Len(sB)
sM = CStr(CLng(Mid(sB, Len(sB) - i + 1, 1)) * CLng(sA))
With rngA.Resize(, rngA.Count + 1).Offset(1 + i, -i)
For j = 1 To Len(sM)
.Cells(.Count - j + 1).Value = Mid(sM, Len(sM) - j + 1, 1)
Next
If i = 1 Then .Borders(xlEdgeTop).LineStyle = xlContinuous
End With
Next
'計算結果
sRslt = CStr(CLng(sA) * CLng(sB))
Set rngRslt = rngA.Offset(2 + Len(sB), -Len(sB)).Resize(, Len(sA) + Len(sB))
With rngRslt
.Borders(xlEdgeTop).LineStyle = xlContinuous
For i = 1 To Len(sRslt)
.Cells(.Count - i + 1).Value = Mid(sRslt, Len(sRslt) - i + 1, 1)
Next
End With
End Sub
複製代碼
作者:
Hsieh
時間:
2014-2-19 23:10
回復
1#
q1a2z5
Sub ex()
Set 被乘數 = [J4:M4]
Set 倍數 = [J5:M5]
ActiveSheet.UsedRange.Offset(倍數.Row, 0).ClearContents '清除
n = Val(Join(Application.Transpose(Application.Transpose(被乘數)), ""))
m = Val(Join(Application.Transpose(Application.Transpose(倍數)), ""))
k = 被乘數.Column + 被乘數.Count - 1: r = 倍數.Row + 1
Do While IsNumeric(Cells(5, k)) And Cells(5, k) <> ""
s = n * Cells(5, k)
For i = Len(s) To 1 Step -1
Cells(r, k - (Len(s) - i)) = Val(Mid(s, i, 1))
Next
r = r + 1
k = k - 1
Loop
For i = Len(n * m) To 1 Step -1
Cells(r, 13 - (Len(n * m) - i)) = Val(Mid(n * m, i, 1))
Next
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)