close

Is it possible to total the number of digits in a single cell? e.g. if a
cell contains the number 23456 can you put a maths function in another
cell to display the total i.e 20? Many thanks.--
stevo
------------------------------------------------------------------------
stevo's Profile: www.excelforum.com/member.php...oamp;userid=10737
View this thread: www.excelforum.com/showthread...hreadid=512178Here you go

=SUMPRODUCT(--(MID(A1,ROW(INDIRECT(quot;1:quot;amp;LEN(A1))),1)))

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

quot;stevoquot; gt; wrote in
message ...
gt;
gt; Is it possible to total the number of digits in a single cell? e.g. if a
gt; cell contains the number 23456 can you put a maths function in another
gt; cell to display the total i.e 20? Many thanks.
gt;
gt;
gt; --
gt; stevo
gt; ------------------------------------------------------------------------
gt; stevo's Profile:
www.excelforum.com/member.php...oamp;userid=10737
gt; View this thread: www.excelforum.com/showthread...hreadid=512178
gt;

Hi Stevo,

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

To use this UDF, press [alt F11], [ctrl R], go to Insert - Module,
amp; 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
quot;=sum_digits(A1)quot; into cell B2 amp; you should see 20 appear in cell B1.For more tips/background amp; a link see:
www.excelforum.com/showthread.php?t=507919, amp;
www.excelforum.com/showthread...ion.Vola tilehth,
Rob Brockett
NZ
Always learning amp; the best way to learn is to experience...--
broro183
------------------------------------------------------------------------
broro183's Profile: www.excelforum.com/member.php...oamp;userid=30068
View this thread: www.excelforum.com/showthread...hreadid=512178

全站熱搜
創作者介紹
創作者 software 的頭像
software

software

software 發表在 痞客邦 留言(0) 人氣()