'从B列第一行开始逐个统计,结果显示在C列
Sub tj()
For r = 1 To Range("B65536").End(xlUp).Row
Dim a
a = Cells(r, 2)
Dim n
n = Len(a)
Dim x As Integer
For i = 1 To n
x = x + Mid(a, i, 1)
Next
Cells(r, 3) = x
x = 0
Next
End Sub
看你意思是有文本的数字要转换成数字,插入模块,输入以下代码运行
sub 求和()
i=1
do while cells(i,2)<>""
sum=sum+val(cells(i,2))
i=i+1
loop
msgbox sum
end sub
Function He(rng As Range)
For i = 1 To Len(rng)
a = Val(Mid(rng, i, 1))
He = He + a
Next
End Function
都是三位数吗?用函数公式就可以算出来:
=SUMPRODUCT(--MID(B1,ROW($1:$3),1))
信息课上有教啊,初二的