View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
broro183
 
Posts: n/a
Default Adding digits in a single cell


Hi Stevo,

I've just adapted this from a user defined function (UDF) that sorts
the digits in a cell
(http://www.excelforum.com/showthread.php?t=507991).

To use this UDF, press [alt + F11], [ctrl + R], go to Insert - Module,
& paste the following in:


Function sum_digits(s As String) As Long
Application.Volatile 'This forces the function to update
Dim i As Long
For i = 1 To Len(s)
sum_digits = sum_digits + Mid(s, i, 1)
Next i
End Function

Now, if your # (eg 23456) that you want to sum is in A1, enter
"=sum_digits(A1)" into cell B2 & you should see 20 appear in cell B1.


For more tips/background & a link see:
http://www.excelforum.com/showthread.php?t=507919, &
http://www.excelforum.com/showthread...ion.Vola tile


hth,
Rob Brockett
NZ
Always learning & the best way to learn is to experience...


--
broro183
------------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php...o&userid=30068
View this thread: http://www.excelforum.com/showthread...hreadid=512178