標題:
[發問]
請問如何將各欄位數值分割後,再乘上對應碼後加總?
[打印本頁]
作者:
winston219
時間:
2010-12-23 22:34
標題:
請問如何將各欄位數值分割後,再乘上對應碼後加總?
如附檔說明,謝謝![attach]4196[/attach]
作者:
oobird
時間:
2010-12-23 23:14
Sub yy()
Dim rng, arr, t$, w$, i%, j%
With Sheet1
rng = .Range(.[a2], .[g65536].End(3))
t = "12345678901234567890123"
ReDim arr(1 To UBound(rng), 0)
For i = 1 To UBound(rng)
w = rng(i, 2) & rng(i, 3) & rng(i, 4) & rng(i, 5) & rng(i, 6) & rng(i, 7)
For j = 1 To 23
x1 = Mid(w, j, 1) * Mid(t, j, 1)
arr(i, 0) = arr(i, 0) + x1
Next
Next
.[h2].Resize(i - 1, 1) = arr
End With
End Sub
複製代碼
作者:
winston219
時間:
2010-12-23 23:27
oobird大大,您真是太神了! 感謝您~
作者:
Hsieh
時間:
2010-12-23 23:34
小弟也來試試
Sub nn()
For Each a In Range([B2], [B65536].End(xlUp))
mystr = Join(Application.Transpose(Application.Transpose(a.Resize(, 6))), "")
For i = 1 To 23
cnt = cnt + (i Mod 10) * Mid(mystr, i, 1)
Next
a.Offset(, 6) = cnt: cnt = 0
Next
End Sub
複製代碼
作者:
GBKEE
時間:
2010-12-24 11:43
回復
1#
winston219
Sub Ex()
Dim Ar(), Ar1(), A, MyStr, I
For Each A In Range("B2", Range("B" & Rows.Count).End(xlUp).Address)
MyStr = Join(Application.Transpose(Application.Transpose(A.Resize(, 6))), "")
ReDim Ar(Len(MyStr) - 1)
ReDim Ar1(Len(MyStr) - 1)
For I = 1 To Len(MyStr)
Ar(I - 1) = Val(Right(I, 1))
Ar1(I - 1) = Val(Mid(MyStr, I, 1))
Next
A.Offset(, 6) = Application.SumProduct(Ar, Ar1)
Next
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)