Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RMO RMO is offline
external usenet poster
 
Posts: 3
Default Summing a cell containing numbers and text

I have a spreadsheet with a column that contains explanations for changes in
account values day to day. The cells contain numbers, text and abbreviations
for multiples of 1,000 and 1,000,000. For example, one cell might have the
following:

2.375mm wires, 600k p/i, 100.235mm mkt

Is it possible to create a macro that will remove the text, convert the
numbers to their actual values (2,375,000, 600,000 and 100,235,000) and sum
these? The descriptions might not necessarily be in the order they are above
but the abbreviations and descriptions should be consistant.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Summing a cell containing numbers and text

This should get you started.

It assumes the string ends with text as in your example.

Sub Sumstrings()
Dim tot As Double, s As String
Dim i As Long, Mult As Double
s1 = ActiveCell.Text
For i = 1 To Len(s1)
schr = Mid(s1, i, 1)
If IsNumeric(schr) Or schr = "." Then
s = s & schr
Else
If Len(s) 0 Then
Select Case schr
Case "m"
Mult = 1000000
Case "k"
Mult = 1000
Case Else
Mult = 1
End Select
tot = tot + CDbl(s) * Mult
s = ""
End If
End If
Next
MsgBox Format(tot, "#,##0")
End Sub

--
Regards,
Tom Ogilvy


"RMO" wrote:

I have a spreadsheet with a column that contains explanations for changes in
account values day to day. The cells contain numbers, text and abbreviations
for multiples of 1,000 and 1,000,000. For example, one cell might have the
following:

2.375mm wires, 600k p/i, 100.235mm mkt

Is it possible to create a macro that will remove the text, convert the
numbers to their actual values (2,375,000, 600,000 and 100,235,000) and sum
these? The descriptions might not necessarily be in the order they are above
but the abbreviations and descriptions should be consistant.

  #3   Report Post  
Posted to microsoft.public.excel.programming
RMO RMO is offline
external usenet poster
 
Posts: 3
Default Summing a cell containing numbers and text

Thanks so much. I forgot to mention one thing. Negative values would be
presented in parenthesis (i.e. (22k) wires, (1.23mm) mkt). The macro you
gave me doesn't seem to accomodate negative values.

Also, is it possible to write a function so the values can appear in a cell?

Thanks again.




"Tom Ogilvy" wrote:

This should get you started.

It assumes the string ends with text as in your example.

Sub Sumstrings()
Dim tot As Double, s As String
Dim i As Long, Mult As Double
s1 = ActiveCell.Text
For i = 1 To Len(s1)
schr = Mid(s1, i, 1)
If IsNumeric(schr) Or schr = "." Then
s = s & schr
Else
If Len(s) 0 Then
Select Case schr
Case "m"
Mult = 1000000
Case "k"
Mult = 1000
Case Else
Mult = 1
End Select
tot = tot + CDbl(s) * Mult
s = ""
End If
End If
Next
MsgBox Format(tot, "#,##0")
End Sub

--
Regards,
Tom Ogilvy


"RMO" wrote:

I have a spreadsheet with a column that contains explanations for changes in
account values day to day. The cells contain numbers, text and abbreviations
for multiples of 1,000 and 1,000,000. For example, one cell might have the
following:

2.375mm wires, 600k p/i, 100.235mm mkt

Is it possible to create a macro that will remove the text, convert the
numbers to their actual values (2,375,000, 600,000 and 100,235,000) and sum
these? The descriptions might not necessarily be in the order they are above
but the abbreviations and descriptions should be consistant.

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
Summing Text & Numbers bgcooker Excel Discussion (Misc queries) 2 January 21st 10 06:04 AM
Summing Text with Numbers bgcooker Excel Discussion (Misc queries) 5 January 21st 10 12:25 AM
Help with finding numbers within text and summing wallymeister Excel Worksheet Functions 2 December 13th 08 11:25 AM
Summing Numbers and Text in same cell Andrewba Excel Discussion (Misc queries) 3 August 8th 08 03:57 PM
Summing cells that contain numbers and text Mango Excel Discussion (Misc queries) 10 May 13th 06 06:18 PM


All times are GMT +1. The time now is 06:10 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"