VB在excel里面程序设计 关于任何数字的数位之和

来源:百度知道 编辑:UC知道 时间:2024/06/06 16:22:29
Write a Visual Basic program that will take an integer as input and return the sum of that integer’s digits. For example: if the integer 32456 is entered, the result should be 3+2+4+5+6 = 20. The integer can be of variable length (it can have any number of digits). You should use a loop to process the integer.
要有msgbox的设计啊 就是填完数字 然后系统它自己加....

Dim i, l, k As Integer
Dim str As String
l = Len(Cells(1, 1))
For i = 1 To l
k = k + Mid(Cells(1, 1), i, 1)
Next
Cells(1, 2) = k

=SUM(1*MID(A1,ROW(INDIRECT("A1:A"&LEN(A1))),1))
数组公式,CTRL+SHIFT+Enter三键结束