?
Solved

Using substring in excel 2007 to pull out numbers

Posted on 2011-03-02
3
Medium Priority
?
1,152 Views
Last Modified: 2012-05-11
I am using sumifs to add data on a spreadsheet.  The field that I would like to compare is concatanated as follows:

  01 - Red
  02 - Yellow
  03 - Blue
  04 - Green

I would like to compare just to the numeric part of the string when reading the spreadsheet.  What is the substring statement I would use to isolate the numbers.  The string is indented so the numbers are not in columns 1 and 2. It appears there are possibly 2 spaces in front of the numbers.
0
Comment
Question by:morinia
  • 2
3 Comments
 
LVL 50
ID: 35023270
Hello,

you can extract the number like this

=LEFT(A1,FIND("-",A1&"-")-1)+0

cheers, teylyn
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 1000 total points
ID: 35023323
Please find attached a sample with a Sumproduct that counts the occurrences of the numbers in the range.

One option is if the comparison with true numbers (in D2)

=SUMPRODUCT(--(LEFT($A$2:$A$11,FIND("-",$A$2:$A$11)-2)+0=D2))


Another option is the comparison with text, like 01, 02, 03 (in G2)

=SUMPRODUCT(--(TRIM(LEFT($A$2:$A$11,FIND("-",$A$2:$A$11)-1))=G2))

cheers, teylyn
Book3.xls
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 35023340
If you want to retain the leading zeros, you'll need to take a similar approach:

=Trim(Left(A1, Find("-", A1&"-") -1))
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question