tags:

views:

199

answers:

4

Hi All You Amazing People

Update

You know what, I should let you know that I am actually trying to do this with numbers and not alphabets. For instance, I have a field with value like 225566 and I am trying to pick out fields which have 55 in them. It is only now I realize this might make a huge difference

ColumnA | ColumnB |
225566 | 2
125589 | 3
95543 | 2

(Below is what I had asked first and later realized I wasn't asking the right question.) *Lets say I have a table as

ColumnA | ColumnB |
AABBC | 2
AADDC | 3
ZZBBC | 2

Now how could I get a SUMIF for those rows where Column A has a field with BB in it? Assume that there are hundreds of rows. I realize that I have to borrow something conceptually from the way text to column is done. But I wonder if anyone would know how I could do this. Thanks a lot.*

+1  A: 

In Excel 2003 and 2007 (and possibly earlier versions, I cannot test), you can use * as a wildcard character in the match. For example, with your sample data set C1 to

=SUMIF(A1:A3,"*BB*",B1:B3)

and you should see the value 4.

DocMax
Hey DocMax, I tried this and it isn't working on my data.
Sriram
You know what, I should let you know that I am actually trying to do this with numbers and not alphabets. For instance, I have a field with value like 225566 and I am trying to pick out fields which have 55 in them. It is only now I realize this might make a huge difference.
Sriram
+2  A: 

Since you're trying to do this on numbers, you'll need to use an array formula.

If your test values are in A3:A5 and your values to sum are in B3:B5, this will work:

=SUM( IF(ISERROR(FIND("55", TEXT(A3:A5,"#"))), 0, 1) * B3:B5 )

When entering an array formula, use Ctrl-Shift-Enter rather than just hitting Enter.

This sums the product of the sum value and a 0 or 1 from the IF() statement, which tests whether or not each test value, after being converted to text, contains a "55".

richardtallent
Hey Richard, can you please explain the importance of the pound sign? Thanks a bunch.
Sriram
The TEXT() function requires two arguments, the second is a template to be used to convert the number to text. The pound sign is a formatting string indicating the value should be rendered as a number. More information: http://office.microsoft.com/en-us/excel/HP052093131033.aspx
richardtallent
I don't know why this doesn't work for me. Anyway I can upload my file? Thanks
Sriram
it works! i was hitting shift-enter instead of ctrl-shift-enter. thanks a lot docmax, richardtallent, benmccormack, civic.
Sriram
Hey Richard, if I wanted to count instead of sum what should I do? I tried this, but it didn't work. Please let me know if possible. Thanks =COUNT( IF(ISERROR(FIND("55", TEXT(A3:A5,"#"))), 0, 1) * B3:B5 )
Sriram
For a simple count, keep the SUM but remove the "* B3:B5" part. That removes the multiplication, leaving only a sum of 1's for rows that have the "55" and 0's for those that don't.
richardtallent
Yeah, I realized that Cilvic had already given em a solution to that. Thank again Richard. You'll are saving some people days over days!
Sriram
+2  A: 

I think you will need an matrix/array formular to do this:

{=SUM(IF(ISERROR(FINDEN("55";A2:A4;1));0;1))}

The weird brakets {} indicate it is an matrix formular you get them by pressing SHIFT+CTRL+RETURN instead of Return when editing the formula.

This formula will cycle through the range A2:A4, check if it finds "55" inside and if so add 1 to the sum.

Google array/matrix formulas as they are not self explanatory.

Best

Jan

Cilvic
JanThanks a lot. You've given me the solution to counting the number of times a column has a numeric value which might have a specific numbers within it. This was going to be my next question. But it did not work for me when I pasted your formula, I think there were minor syntax issues. I changed the semicolons to commas and it worked =SUM(IF(ISERROR(FIND("55", A2:A4, 1)), 0, 1)). thanks a lot
Sriram
A: 

Create a 3rd column (ColumnC) and put this formula in it:

=Text(A2,0)

Drag that column down to complete your column. This will format the value as text. Next, use SUMIF as DocMax explained, except with different columns:

=SUMIF(C1:C3,"*BB*",B1:B3)

The reason you do this is because you need to be reading a Text value, not a Number value when using the *BB* comparison of SUMIF. Great question.

Ben McCormack
Thanks for your help Ben. But for some reason this approach isn't working for me as I have mentioned as a comment to richardtallent. Looking forward to continued help from you all! Thank you so much.
Sriram