Summing up digits in a cell

S

Sai Krishna

Hi,

i need to add all the digits in a cell. For example, if I have a number 58
in a cell, the adjacent cell should return a value of 13.
regards
krishna
 
G

Gary''s Student

Try this small UDF:

Function digicount(r As Range) As Integer
Dim n As Integer
digicount = 0
v = r.Value
L = Len(v)
For i = 1 To L
n = Mid(v, i, 1)
digicount = digicount + n
Next
End Function
 
S

Sai Krishna

Thanks a ton Brad. Was looking for something as useful and simple as this.
regards
krishna
 
D

Dana DeLouis

... this has helped for two digits.

Another option for 1-2 digit numbers ...

=A1-9*INT(A1/10)

--
Dana DeLouis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top