Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Counting mixed chains of numbers and letters

Is there a way to sum the numerical values in a chain that includes numbers
and letters.

Example.
If I have a chain such as "M4G3M4P0" is there something I can do so that
excel will sum the numerical values? Note: the chains I am working with are
sometimes quite long (up to 25 characters) but almost always go
letter-number-letter-number- and so on.

Thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Counting mixed chains of numbers and letters

Sub Sumcharacters()
Dim i as Long, s as String
Dim lsum as Long
for i = 1 to len(cell.value)
s = Mid(cell.value,i,1)
if isnumeric(s) then
lsum = lsum + clng(s)
end if
Next
msgbox lsum
End Sub

--
Regards,
Tom Ogilvy


"Dave" wrote:

Is there a way to sum the numerical values in a chain that includes numbers
and letters.

Example.
If I have a chain such as "M4G3M4P0" is there something I can do so that
excel will sum the numerical values? Note: the chains I am working with are
sometimes quite long (up to 25 characters) but almost always go
letter-number-letter-number- and so on.

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Counting mixed chains of numbers and letters

Tom-
Thank you for the code for VB. I am fairly unfamiliar with VB though, if my
string of "M4G3 M4P0" was in cell B4, what in the VB code do I need to
change. Can I change the code so it evaluates a range of cells?
Thanks again


"Tom Ogilvy" wrote:

Sub Sumcharacters()
Dim i as Long, s as String
Dim lsum as Long
for i = 1 to len(cell.value)
s = Mid(cell.value,i,1)
if isnumeric(s) then
lsum = lsum + clng(s)
end if
Next
msgbox lsum
End Sub

--
Regards,
Tom Ogilvy


"Dave" wrote:

Is there a way to sum the numerical values in a chain that includes numbers
and letters.

Example.
If I have a chain such as "M4G3M4P0" is there something I can do so that
excel will sum the numerical values? Note: the chains I am working with are
sometimes quite long (up to 25 characters) but almost always go
letter-number-letter-number- and so on.

Thank you

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Counting mixed chains of numbers and letters

Sub Sumcharacters()
Dim i as Long, s as String
Dim lsum as Long, cell as range

set cell = Range("B4")
for i = 1 to len(cell.value)
s = Mid(cell.value,i,1)
if isnumeric(s) then
lsum = lsum + clng(s)
end if
Next
msgbox lsum
End Sub


Sub SumcharactersMultipleCells()
Dim i as Long, s as String
Dim lsum as Long, cell as Range
set cell = Range("B4").Resize(5,20)
for each cell in rng
for i = 1 to len(cell.value)
s = Mid(cell.value,i,1)
if isnumeric(s) then
lsum = lsum + clng(s)
end if
Next
Next cell
msgbox lsum
End Sub

--
Regards,
Tom Ogilvy

"Dave" wrote:

Tom-
Thank you for the code for VB. I am fairly unfamiliar with VB though, if my
string of "M4G3 M4P0" was in cell B4, what in the VB code do I need to
change. Can I change the code so it evaluates a range of cells?
Thanks again


"Tom Ogilvy" wrote:

Sub Sumcharacters()
Dim i as Long, s as String
Dim lsum as Long
for i = 1 to len(cell.value)
s = Mid(cell.value,i,1)
if isnumeric(s) then
lsum = lsum + clng(s)
end if
Next
msgbox lsum
End Sub

--
Regards,
Tom Ogilvy


"Dave" wrote:

Is there a way to sum the numerical values in a chain that includes numbers
and letters.

Example.
If I have a chain such as "M4G3M4P0" is there something I can do so that
excel will sum the numerical values? Note: the chains I am working with are
sometimes quite long (up to 25 characters) but almost always go
letter-number-letter-number- and so on.

Thank you

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
I receive Exel file it is mixed numbers & letters Not English John Excel Discussion (Misc queries) 2 November 28th 09 04:42 PM
Counting how many numbers and letters appear in a particular row dcb1 Excel Discussion (Misc queries) 7 August 21st 09 08:00 AM
The order of numbers mixed with letters sgg Excel Discussion (Misc queries) 1 September 25th 08 10:55 PM
Sort mixed numbers/letters V-ger Excel Discussion (Misc queries) 1 November 14th 05 10:49 PM
Counting numbers and letters Sean[_9_] Excel Programming 2 October 23rd 04 12:09 AM


All times are GMT +1. The time now is 11:09 PM.

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"