Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
DMG
 
Posts: n/a
Default summing characters in a string

Hi
Is there a way to sum the characters in a string. For example A1 contains
12345. I would like a formula to return 15 (1+2+3+4+5).
As an added twist, the string is variable length.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
David Billigmeier
 
Posts: n/a
Default summing characters in a string

Assume your cell to use is A1, this formula will work. Enter it using
CTRL+SHIFT+ENTER as it is an array formula:

=SUM(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))


--
Regards,
Dave


"DMG" wrote:

Hi
Is there a way to sum the characters in a string. For example A1 contains
12345. I would like a formula to return 15 (1+2+3+4+5).
As an added twist, the string is variable length.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Norman Jones
 
Posts: n/a
Default summing characters in a string

Hi DMG,

You could use a user defined function (UDF):

'=============
Public Function SumChars(aCell As Range)

Dim i As Long
Dim vVal As Variant

vVal = aCell.Value

If Not IsError(vVal) Then
For i = 1 To Len(aCell)
If IsNumeric(Mid(vVal, i, 1)) Then
SumChars = SumChars + CLng(Mid(vVal, i, 1))
End If
Next i
Else
SumChars = CVErr(xlErrNA)
End If

End Function
'<<=============

Usage: =SumChars(A1)

If you are not familiar with UDFs, you may wish to visit David McRitchie's
'Getting Started With Macros And User Defined Functions' at:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


---
Regards,
Norman


"DMG" wrote in message
...
Hi
Is there a way to sum the characters in a string. For example A1 contains
12345. I would like a formula to return 15 (1+2+3+4+5).
As an added twist, the string is variable length.

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
DMG
 
Posts: n/a
Default summing characters in a string

That is perfect. Thank you for your help.

"David Billigmeier" wrote:

Assume your cell to use is A1, this formula will work. Enter it using
CTRL+SHIFT+ENTER as it is an array formula:

=SUM(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))


--
Regards,
Dave


"DMG" wrote:

Hi
Is there a way to sum the characters in a string. For example A1 contains
12345. I would like a formula to return 15 (1+2+3+4+5).
As an added twist, the string is variable length.

Thanks

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernard Liengme
 
Posts: n/a
Default summing characters in a string

Without the need to use SHIFT+CTRL+ENTER,
=SUMPRODUCT(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))
best wishes
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email


"DMG" wrote in message
...
Hi
Is there a way to sum the characters in a string. For example A1 contains
12345. I would like a formula to return 15 (1+2+3+4+5).
As an added twist, the string is variable length.

Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting a character from a string of characters Sue Excel Discussion (Misc queries) 6 October 30th 05 01:35 AM
select a string of characters Did Excel Worksheet Functions 7 August 17th 05 04:24 AM
trim a string by specific number of characters windyoldman Excel Discussion (Misc queries) 2 July 13th 05 01:53 PM
Remove characters from a text string using a formula duncrbrt Excel Discussion (Misc queries) 1 June 4th 05 02:19 AM
Read Text File into Excel Using VBA Willie T Excel Discussion (Misc queries) 13 January 8th 05 12:37 AM


All times are GMT +1. The time now is 01:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"