举例:B1公式:=sum(a1:a5)
VBA写法:
Sub iSum() Dim c As Range, s, tmp s= 0 For Each c In Range("A1:A5") tmp = c If IsNumeric(tmp) Then s = s + tmp Next Range("B1") = sEnd Sub
VBA可以直接引用工作表的求和函数,例如WORKSHEET.FUNCTION