Excel: extract and sum numerals from mixed text/numeral cell range

I have a large (30x20) grid of cells with data, and I want to extract
and then sum up certain numerals from this entire range.  The catch is
that the data is mixed numerals and text, as you'll see below.

Here's an abbreviated 3x3 example, with a value in each of the nine
cells:

V7.1   T     H
P1      A     T
B        V3   P4.5

If I just wanted to sum up the instances of "T" appearing, I could use
COUNTIF() for the entire range to come up with answer ("T" appears 2
times).  Easy enough.

But, what I'm trying to accomplish is to sum up the numerals associated
with other letters. Specifically, I'd like to sum up the numbers
associated with the letter "V"; there are two entries above, "V7.1" and
"V3", so I'd like to chop off the letters and sum the numerals.  The
answer would be 10.1 (the sum of 7.1 and 3). 

But how would I do this programmatically?

-- B.


---
Message posted from http://www.ExcelForum.com/

0
1/8/2004 9:04:00 PM
excel 39879 articles. 2 followers. Follow

3 Replies
4550 Views

Similar Articles

[PageSpeed] 13

On Thu, 8 Jan 2004 15:04:00 -0600, bssmith
<<bssmith.zqe8m@excelforum-nospam.com>> wrote:

>I have a large (30x20) grid of cells with data, and I want to extract
>and then sum up certain numerals from this entire range.  The catch is
>that the data is mixed numerals and text, as you'll see below.
>
>Here's an abbreviated 3x3 example, with a value in each of the nine
>cells:
>
>V7.1   T     H
>P1      A     T
>B        V3   P4.5
>
>If I just wanted to sum up the instances of "T" appearing, I could use
>COUNTIF() for the entire range to come up with answer ("T" appears 2
>times).  Easy enough.
>
>But, what I'm trying to accomplish is to sum up the numerals associated
>with other letters. Specifically, I'd like to sum up the numbers
>associated with the letter "V"; there are two entries above, "V7.1" and
>"V3", so I'd like to chop off the letters and sum the numerals.  The
>answer would be 10.1 (the sum of 7.1 and 3). 
>
>But how would I do this programmatically?
>
>-- B.

Well, here's a simple UDF that will do it, provided your data is in the format
you show above.

To enter the UDF, <alt><F11> opens the Visual Basic Editor.  Ensure your
project is highlighted in the Project Explorer, then Insert/Module and paste
the code below into the window that opens.

To use this, enter the function =SumDigByLtr(rg,ltr) where rg is the range you
wish to check, and ltr is the letter you want to get the sum for.  The letter
is case sensitive and must be enclosed in quotes.

e.g :   	=sumdigbyltr(E4:G6,"P")

===================
Option Explicit
Function SumDigByLtr(rg As Range, ltr As String) As Double
Dim c As Range

For Each c In rg
    If InStr(1, c.Text, ltr) > 0 Then
        SumDigByLtr = SumDigByLtr + Replace(c.Text, ltr, "")
    End If
Next c
End Function
=====================

--ron
0
1/8/2004 9:30:26 PM
B

Something like the following will do it. (Copy it to a standard module in
the workbook and then use it like a normal function), e.g if the data is in
A1:C3 and you are looking for cells beginning "P"

=sumvalues(A1:C3,"P")

In your example gives an answer of 5.5


Function SumValues(rArea As Range, sLetter As String) As Double
Dim myCell As Range
Dim dTempVal As Double
Application.Volatile True
For Each myCell In rArea
If Left(myCell.Value, 1) = sLetter Then
dTempVal = dTempVal + Mid(myCell.Value, 2, Len(myCell.Value) - 1)
End If
Next myCell
SumValues = dTempVal
End Function


-- 
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS


"bssmith >" <<bssmith.zqe8m@excelforum-nospam.com> wrote in message
news:bssmith.zqe8m@excelforum-nospam.com...
> I have a large (30x20) grid of cells with data, and I want to extract
> and then sum up certain numerals from this entire range.  The catch is
> that the data is mixed numerals and text, as you'll see below.
>
> Here's an abbreviated 3x3 example, with a value in each of the nine
> cells:
>
> V7.1   T     H
> P1      A     T
> B        V3   P4.5
>
> If I just wanted to sum up the instances of "T" appearing, I could use
> COUNTIF() for the entire range to come up with answer ("T" appears 2
> times).  Easy enough.
>
> But, what I'm trying to accomplish is to sum up the numerals associated
> with other letters. Specifically, I'd like to sum up the numbers
> associated with the letter "V"; there are two entries above, "V7.1" and
> "V3", so I'd like to chop off the letters and sum the numerals.  The
> answer would be 10.1 (the sum of 7.1 and 3).
>
> But how would I do this programmatically?
>
> -- B.
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>


0
1/8/2004 9:35:49 PM
You could do it with worksheet functions, too:

=SUM(IF(ISNUMBER(--SUBSTITUTE(UPPER(A1:C1925),"V","")),
                       --SUBSTITUTE(UPPER(A1:C1925),"V","")))

(all one cell, adjust the range accordingly)

This is an array formula.  Hit ctrl-shift-enter instead of enter.  If you do it
correctly, excel will wrap curly brackets {} around your formula.  (don't type
them yourself.)

"bssmith <" wrote:
> 
> I have a large (30x20) grid of cells with data, and I want to extract
> and then sum up certain numerals from this entire range.  The catch is
> that the data is mixed numerals and text, as you'll see below.
> 
> Here's an abbreviated 3x3 example, with a value in each of the nine
> cells:
> 
> V7.1   T     H
> P1      A     T
> B        V3   P4.5
> 
> If I just wanted to sum up the instances of "T" appearing, I could use
> COUNTIF() for the entire range to come up with answer ("T" appears 2
> times).  Easy enough.
> 
> But, what I'm trying to accomplish is to sum up the numerals associated
> with other letters. Specifically, I'd like to sum up the numbers
> associated with the letter "V"; there are two entries above, "V7.1" and
> "V3", so I'd like to chop off the letters and sum the numerals.  The
> answer would be 10.1 (the sum of 7.1 and 3).
> 
> But how would I do this programmatically?
> 
> -- B.
> 
> ---
> Message posted from http://www.ExcelForum.com/

-- 

Dave Peterson
ec35720@msn.com
0
ec35720 (10082)
1/8/2004 11:54:27 PM
Reply:

Similar Artilces:

Check current cell is empty
Hi, I'm getting stuck... If I enter some new data in Sheet2, column A, then this cell will be copied to last cell of sheet 1 columnA automatically. This task can be done now IF the data is overwriting some existing data, no need to copy. my logic is if the active cell is empty, and the target column is 1, then do the copy and paste. else, do nothing The question is: how can I check the current cell is empty? Thank you in Advance Bobocat Sub tester() If IsEmpty(ActiveCell) Then MsgBox "Activecell Is Empty" Else MsgBox "Activecell Is Not Empty&quo...

Auto-format in Microsoft Excel.
Each time i try to enter a number range, for example, 8- 10, in Excel, it constantly re-formats it to a date. If I change the formatting to "General" it turns it into a random number, usually 38209. I would like to turn off ALL auto-formatting, but that's probably asking too much. How do I disable this frustrating feature? thanks. Hi Paul When you enter "8-10" in a cell, that's not strictly a number but Excel thinks you mean a date so converts it as such. A date is a number and in your example the number 38209 represents August 10 2004 which is not a ra...

move cell contents
Is there a way to move a cell contents to another cell with a formula. ex: if a5="Name" then move g5 to j5? Also, I am using =INDEX(Sheet1!B3:B12,INT((RAND()*10)+1),1) to pick random names from a list. I have the formula in different place pick random names from different list. This does work, but I have different list with some of the same names and with the random pick I do not want the same name to appear. -- Thanks for any and all help. Davidl Hi David a formula can only affect the cell it is in, it can't move or change another cell for this you need some code ...

Excel not Access
I have designed an Access database that holds records relating to my stores audit results going back for about 5 years plus a load more information relating to these stores. This was used to produe a pack once a month, however a change in senior management means that I have got to shelve this and prodce a similar pack in Excel. The idea would be that the user could select a month or a 12 mnth date range that would produce data that could then be used to populate a number of excel templates that have been designed. Having not used excel for years I would be grateful for any suggestion...

How to keep format when importing Excel into SQL.
Can anybody help me please? When I import Excel file into SQL, a field that formated as 0000000000 (custom), loosing leading zeros. I tried to change data type in SQL after importing. No luck. I appretiate any help. See if using IMEX=1 helps: http://pratchev.blogspot.com/2007/10/importing-excel-data-into-sql-server.html -- Plamen Ratchev http://www.SQLStudio.com Plamen, I tried this, but got an error: "The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered." Thank you very much for looking into this. "Plamen Ratchev" wr...

Excel 2007
When I select cells to copy as a picture in Excel 2007, the resolution is terrible. Text and objects with shadow's are very blotchy when pasting the picture. How do you change the resolution of a 'Copy Picture'? ...

visible cell only
I'd like to use the PERCENTILE function in a list that has been autofiltered and get the results based only on the visible cells. I've used SUBTOTAL in order to get count, average, min and max. But I need to get the .25 and .75 percentile figures for the filtered data (visible cells only). I've scoured these forums. I've scoured the web. I've found some vba code that was supposed to select only visible cells but it doesn't work for me. I posted last week in the programming section of these forums (and again this morning) but got no reply. I figure...

Using part of a cell in a chart title
I have a chart which should get a title. However, this should be partly be used from a cell e.g. "counted with 5%" 5% should be taken from the cell and used in the title. Is this possible? Hi, Yes it's possible but all of the chart title needs to be in the cell. So you may need to use a helper cell and concatenate text and value. http://www.andypope.info/tips/tip001.htm Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Nicole" <Nicole@discussions.microsoft.com> wrote in message news:5CB7A971-AA7F-4C34-BB42-7DC283AA2958@micro...

Input Excel 'Password to Open' through control in access form
Hi All, We know,Excel has prompt password to open it files. Is it possible to create a code that can supplies the excel prompt password?.So that when we open the excel file through our access control in a form, the excel files can be opened automatically.But when the excel files opened from its default icon,it will prompt a password first. ...

data input in text box
We have a form which the operator enters data in a text box. Currently we have a 'done' button on the form that the operator clicks to send the text box info to a vba program. How can we send the text box info to the vba program when the operator hits the enter key @ the end of the data entry for the text box? TIA -- _______________________________ In Christ's matchless name ted & colleen n6trf kc6rue Use the control's AfterUpdate event. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "ted" <n6trf@arr...

how do I automatically update a text box in a chart?
Hi, You can link the textbox to a cell. When you update the cell the textbox should reflect this. Select the textbox border and then in the formula bar enter the complete cell reference, for example, =Sheet1!A1 Cheers Andy Kath wrote: -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info ...

How To Copy MS Word mailing labels into Excel
I have a word doc that I want to put into Excel. I want to add some more fields to the names and addresses. Is this simple or do I have to learn how to program? Michael Rodriguez City of Grand Prairie Michael, have you tried to copy and paste the data into excel? -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2000 & 97 ** remove news from my email address to reply by email ** "Michael Rodriguez" <mrodrigu@gptx.org> wrote in messa...

How do I use traffic lights in excel
I am wanting to use traffic lights in excel that change colour based on the result of a variance cell, ie if the result of the cell is 10 make the traffic light green, if it is 20 make the traffic light amber, if the result is 30 make the traffic light red. How do I do this? Shorty Format>Conditional Formatting>Cell Value is: Note: you can add up to 3 conditions(4 if you count default) Gord Dibben Excel MVP On Wed, 22 Dec 2004 16:35:03 -0800, Shorty <Shorty@discussions.microsoft.com> wrote: >I am wanting to use traffic lights in excel that change colour based on the &g...

Lookup text with multiple search criteria
I know how to look up data and text using vlookup and hlookup, what I' like to know is whether there is a way of looking up data based on mor than 1 search criteria; for example If I wanted to look up an item in a 4 column database, I'd us something like this: =VLOOKUP("Apples",A2:D10,4,false) But that only looks for Apples. Say I wanted to lookup data based on subcategory of Apples, e.g. colour. If it was a number, I could use SUMPRODUCT and (assuming named range were in use) do it like this: =SUMPRODUCT((Fruit="Apples)*(Colour="Red")*(Total)) But obvio...

what's the formula for adding symbols in cells?
I have a chart that has blank info in the legend. I want to add an * to indicate something, but just inserting a symbol doesn't work. Any ideas? Thanks. Debi - To add information to the legend, you need to add to a series name. Right click on the chart, select Source Data from the pop up menu, click on the series tab, select a series, and either type something in the name box, or click in it and select a cell with the mouse. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services http://PeltierTech.com/Excel/Charts/ _______ Debi wrote: > I have a chart tha...

Unexpected error message on closing an Excel file
Suddenly I am getting the following message when I try to close a workbook: "Your formula contains an invalid external reference to a worksheet. Verify that the path, workbook, and range name or cell reference are correct, and try again" The mysterious thing is that it does not happen consistently and that, after I click OK after the above message, I can still save the file. What might be the cause of this error message and can the "invalid reference" be tracked down using one of the utility add-ins such as J. Walkenbach's PUP? If it only happens when you close ...

help with simple maths in excel
I want to do a simple arithmatic excercise in excel for my grand daughter. It is stuff like 2+2 =4 Smart me has hit a problem at the first hurdle... I need to put 2 in one cell the + in another cell and then 2 in another = in another and then she puts the answer in the next one. So the above would have 4 cells completed and she would put the answer in the 5th one. When I use the + or = sign in a cell of its own it (excel) thinks I am doing an equation, is there a way around this? I will work on the answer like if she gets it correct or wrong how I will do that...a sound or som...

How to change font size on formula bar in Excell 2007
I don't find Tools>Options>General (as suggested in other post answers) in Excel 2007. On the Office button there is an Excel Options but it doesn't provide a method of changing font size on the office but. My font is so small I can barely see it. Office button>ExcelOptions>Popular tab>in the "When creating new workbooks" section, choose font and font size -- Kind regards, Niek Otten Microsoft MVP - Excel "jimwillie" <jimwillie@discussions.microsoft.com> wrote in message news:588AAC05-0F52-404E-AA01-128E70E02D0B@microso...

Opening Excel Workbooks
I'm running into an issue where if I click on an Excel file through My Documents, it doesn't automatically bring it up. I get the toolbar but the actual spreadsheet doesn't appear on the screen. I have to click on the taskbar to get it to pop up. If I already have Excel active and I open a file through Excel, this doesn't happen. Any ideas? Here is a similar thread: http://www.excelforum.com/showthread.php?s=&threadid=237195 Rolli -- Message posted from http://www.ExcelForum.com Hi, Take a look at Tools-Options-General tab- uncheck ignore other application...

How do I merge cells with multiple data values?
I've tried highlighting the two cells which are in the same row. It suggested that I format and align. Both of which I've tried. I keep getting the same error message, "The selection contains multiple data values. Merging into one cell will keep the upper-most data only." I need to make the cells one with all my information. Is this possible? Not knowing what you want to do, let me make a suggestion. Put all your data into the first cell and leave the second cell empty. Select both cells. Click on Format - Cells - Alignment tab. In the "Horizontal" b...

Excel DNS query
Hello, Is there a way for an Excel function to query a DNS server? Thanks. Soundy Not that I know of, but you can turn on the macro recorder, use 'get external data' and tailor the resulting code into a user function of your own. E.g. I've used this to create a button to get MS-Access data from a query that has the same name as the sheet (tab) name. It saves me a lot of copy-paste actions. Bas Hartkamp <soundy@gmail.com> schreef in bericht news:1151940450.029823.127570@j8g2000cwa.googlegroups.com... > Hello, > > Is there a way for an Excel function ...

outputting values to a range from one formula
I wish to generate a table automatically by means of a single formula that applies an iteration on a starting given value with a given step, and the computed values are posted/entered automtically into cells from a given cell onwards, say below it, until the computed value reaches a certain given limt. This is somehow the inverse of INDIRECT or of OFFSET. These can pull values from a variable addresses of cells. What I need is to push values into a variable addresses of cells. Can anyone help me on that?? Thanks. :confused -- Shafe ---------------------------------------------------------...

[b]Can I download Excel data to a MS Access database?[/b]
I've built an Excel 2002 form that I want our internal customers to access from our intranet, and use. Once completed, they will send it to us as an e-mail attachment. I'd like to be able to open it, and somehow download the data from the form into an MS Access 2002 database I've built (so that we don't have to rekey it into the database). Is this possible or even feasible? Any and all help is appreciated. Thanks. :D --------- Message sent via www.excelforums.com Hi in Access check 'File - Import External data' -- Regards Frank Kabel Frankfurt, Germany "...

Excel Problem
I have a 23.8 meg excel 2000 spreadsheet set for manual calculation saved to my local hard drive. Every time I try to open it, it takes forver and sometimes never opens but I do not get any error messages, let me just tell you that I am running a P4, 1 GB memory, Office 2K with SP3, and nothing else running when I try to open it. As I said it is set for manual calculation, and it is cleared to not auto calculate when opening or closing. Any idea's as to why this is happening? -- Todd I don't know why you're having this problem but I would like to point something out for w...

Can you only merge up to a certain number of cells
I am working on microsoft excel 2003, I have a sheet that I merged cells starting with line 8 through 43...when I type my information in the merged area I can see all that I am typing...say it goes up to line 30 once I hit the enter key I can only see up to line 20. Even when I print it out it only prints up to line 20...I have checked to make sure there are not locked cells etc. I cannot figure out at all why this is happening...is there only up to a certain number of cells you can merge? From "Excel Specifications and Limits" Length of cell contents (text) ...