![]() |
Sum of digits in a number
Example: a number 1234 would sum individual dighits to a value of 10.
I thought there would be a function in Excel that would do that but can't seem to find it. I don't want write a macro with MID functions to do the summing. Is there such a function in Excel? Thank you in advance for any help |
Sum of digits in a number
Hi Bob
there is no direct function, but you could use the following: =SUMPRODUCT(MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1)*1) hth Carlo On Jan 8, 9:17*am, Bob Ptacek wrote: Example: a number 1234 would sum individual dighits to a value of 10. I thought there would be a function in Excel that would do that but can't seem to find it. I don't want write a macro with MID functions to do the summing. Is there such a function in Excel? Thank you in advance for any help |
Sum of digits in a number
Bob
=SUMPRODUCT(--MID($A$1,ROW(INDIRECT("1:" & LEN($A$1))),1)) I forget who originally posted this, but well done! Gord Dibben MS Excel MVP On Mon, 7 Jan 2008 16:17:02 -0800, Bob Ptacek wrote: Example: a number 1234 would sum individual dighits to a value of 10. I thought there would be a function in Excel that would do that but can't seem to find it. I don't want write a macro with MID functions to do the summing. Is there such a function in Excel? Thank you in advance for any help |
Sum of digits in a number
Is there such a function in Excel?
Afaik, no. but simple enough to create. Public Function StringSum(str As String) As Long Dim i As Integer For i = 1 To Len(str) StringSum = StringSum + Mid(str, i, 1) Next i End Function A1: 1234 B1: =StringSum(A1) B1 should display 10 -- HTH, George "Bob Ptacek" wrote in message ... Example: a number 1234 would sum individual dighits to a value of 10. I thought there would be a function in Excel that would do that but can't seem to find it. I don't want write a macro with MID functions to do the summing. Is there such a function in Excel? Thank you in advance for any help |
All times are GMT +1. The time now is 04:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com