# Count cells with “Apple” only in rows that matches the name

#### kevkev

##### New Member
I'm trying to create a spreadsheet that counts the number of a particular occurrence on a row only when it matches the name.

Cover Sheet
 Col A Col B Row 1 BOB =SUMPRODUCT((General!\$A:\$A=Cover!A1)*((General!\$B:\$FZ="Apple"))) Row 2 JANE Row 3 JOE Row 4 JOHN

General Sheet
 Col A Col B Col C ...Col FZ Row 1 JANE Apple Orange Apple Row 2 BOB Orange Apple Orange Row 3 JOHN Apple Apple Apple Row 4 JOE Orange Apple Apple

So far I have this formula =SUMPRODUCT((General!\$A:\$A=Cover!A1)*((General!\$B:\$FZ="Apple"))) which works well for small data but it gives the "Excel ran out of resources while attempting to calculate one or more formulas. As a result, these formulas can not be evaluated." when applied to big data (200 rows and 160 columns. File size 97kb). The result of this formula is '1', which is what's expected. I've tried to convert "CountIf" but I can't get it to give the expected results. Help please!

### Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

#### Fluff

##### MrExcel MVP, Moderator
Never you whole columns in an array formula, you should always limit them to the data, or a few rows extra.
Try
=SUMPRODUCT((General!\$A1:\$A500=Cover!A1)*((General!\$B1:\$FZ500="Apple")))

#### kevkev

##### New Member
Thanks Fluff. Reducing the number of rows worked like magic. It actually skipped my mind cos when I used the whole columns and rows on CountIf, it didn't throw the "ran out of resources" error, just the formula I tried using was giving the wrong result. Can this formula be converted to a CountIf??

#### Fluff

##### MrExcel MVP, Moderator
Can this formula be converted to a CountIf??
You would need to use Countifs rather than Countif, but not sure it could be done. Sumproduct is probably the better option.

#### kevkev

##### New Member
Oh! Okay. I've tried both CountIf and CountIfs but I couldn't get it to work. I'll do with this SumProduct solution. Thanks again for your help!

#### Fluff

##### MrExcel MVP, Moderator
You're welcome & thanks for the feedback

Replies
3
Views
359
Replies
3
Views
48
Replies
1
Views
198
Replies
5
Views
63
Replies
7
Views
120

1,137,124
Messages
5,679,746
Members
419,855
Latest member
Eddier32

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back