Example:
A cell contains the value 1234
My function would add 1+2+3+4 = 10
then add 1+0 = 1
Does anyone know of a way to do this?
=SUMPRODUCT(--(MID(A2,ROW(INDIRECT("1:" & LEN(A2))),1)))
where A2 holds 1234
--
Regards,
Peo Sjoblom
"Kevin" <sonn...@aol.com> wrote in message
news:00eb01c3337c$783498a0$a401...@phx.gbl...
In B1 enter & copy to D1...
=IF((LEN(A1)>=1)*(LEN(A1)<=15),SUMPRODUCT(MID(A1,ROW(INDIRECT("1:"&LEN(A1)))
,1)+0),"")
D1 will house the desired single-digit result.
"Kevin" <sonn...@aol.com> wrote in message
news:00eb01c3337c$783498a0$a401...@phx.gbl...
Function addup(ByVal y As Integer)
a = 0
While y > 0
a = a + y Mod 10
y = Int(y / 10)
Wend
If a > 9 Then
a = addup(a)
End If
addup = a
End Function
>.
>
Function SumDigits(n) As Double
'// Dana DeLouis
Const dgts As String = "#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#"
SumDigits = Round(n, 0)
Do While SumDigits > 9
SumDigits = Evaluate(Format(SumDigits, dgts))
Loop
End Function
HTH.
--
Dana DeLouis
Windows XP & Office XP
= = = = = = = = = = = = = = = = =
"Kevin" <sonn...@aol.com> wrote in message
news:00eb01c3337c$783498a0$a401...@phx.gbl...
Assuming integers numbers of 1 to 15 digits:
=SUMPRODUCT(--(MID(SUMPRODUCT(--(MID(A1,ROW(INDIRECT("1:" &
LEN(A1))),1)))&"00",ROW(INDIRECT("1:3")),1)))
Regards,
Daniel M.
"Kevin" <sonn...@aol.com> wrote in message
news:00eb01c3337c$783498a0$a401...@phx.gbl...
Function AddDigits(ByVal X As Double) As Double
Dim A As Double
Dim Y As Double
A = 0
X = Int(Abs(X))
Do While X > 0
Y = Int(X / 10)
A = A + X - Y * 10
If A > 9 Then A = A - 9
X = Y
Loop
AddDigits = A
End Function
Function SumDigits(n) As Double
'// Dana DeLouis
SumDigits = Round(n, 0)
' Mod 9, but for larger numbers
SumDigits = SumDigits - (9 * Int(SumDigits / 9))
SumDigits = SumDigits Mod 9
If SumDigits = 0 Then SumDigits = 9
End Function
--
Dana DeLouis
Windows XP & Office XP
= = = = = = = = = = = = = = = = =
"Myrna Larson" <myrna...@charter.net> wrote in message
news:3q9qevou76mp2jkn2...@4ax.com...
Regards,
Vasant.
"Dana DeLouis" <ng_...@hotmail.com> wrote in message
news:OF3pI87M...@tk2msftngp13.phx.gbl...
On Mon, 16 Jun 2003 00:22:25 -0400, "Dana DeLouis" <ng_...@hotmail.com> wrote:
Life is too short for all the text processing answers you've received so far. If
you need to do this recursively until you get a single decimal digit, and if
you're always starting with positive integers, it's *ALWAYS* going to be
=1+MOD(X-1,9)
If zero is a possible starting value, modify this to
=IF(X>0,1+MOD(X-1,9),0)
Sheesh, you'd think no one remembers their Number Theory.
--
1. Don't attach files to postings in this newsgroup.
2. Snip unnecessary text from quoted text. Indiscriminate quoting is wasteful.
3. Excel 97 & later provides 65,536 rows & 256 columns per worksheet. There are
no add-ins or patches that increase them. Need more? Use something else.
--
Regards,
Peo Sjoblom
"Harlan Grove" <hrl...@aol.com> wrote in message
news:yLqHa.488$cJ5...@www.newsranger.com...
Thanks all- I learned a lot here.
>.
>