PC Review


Reply
Thread Tools Rate Thread

Counting mixed chains of numbers and letters

 
 
=?Utf-8?B?RGF2ZQ==?=
Guest
Posts: n/a
 
      27th Feb 2007
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 With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      27th Feb 2007
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 With Quote
 
=?Utf-8?B?RGF2ZQ==?=
Guest
Posts: n/a
 
      27th Feb 2007
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 With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      27th Feb 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
I receive Exel file it is mixed numbers & letters Not English John Microsoft Excel Misc 2 28th Nov 2009 04:42 PM
The order of numbers mixed with letters sgg Microsoft Excel Misc 1 25th Sep 2008 10:55 PM
Sort mixed numbers/letters =?Utf-8?B?Vi1nZXI=?= Microsoft Excel Misc 1 14th Nov 2005 10:49 PM
Counting numbers and letters Sean Microsoft Excel Programming 2 23rd Oct 2004 12:09 AM
Counting numbers withing a mixed text/number cell Jared Croft Microsoft Excel Discussion 3 18th Jan 2004 03:17 PM


Features
 

Advertising
 

Newsgroups
 


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