Problem using countif and offset when data is contained on two rows (see example)

ShawnLerner

New Member
Joined
Nov 3, 2016
Messages
11
This is a simplified representation of the problem:

How do I write a formula that will count the number of green apples from a dataset like the one below where the odd number rows have fruit type and the even number row right below it has the corresponding fruit colour?


A
1 Apple
2 Green
3 Apple
4 Blue
5 Peach
6 Green
7 Apple
8 Green


In this example the value I want to get is 2. (A1=Apple, A2=Green + A7=Apple, A8=Green)


I think I should be able to do this using Countif and Offset but can't for the life of me figure out how. Any help would be most appreciated!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Thanks but both
=COUNTIFS(A1:A8,"Apple",A2:A9,"Green")
and

=SUMPRODUCT(--($A$1:$A$7="apple"),--($A$2:$A$8="green"))

returned 1 not 2. Any other suggestions would be appreciated.

 
Upvote 0
Thanks but both
=COUNTIFS(A1:A8,"Apple",A2:A9,"Green")
and

=SUMPRODUCT(--($A$1:$A$7="apple"),--($A$2:$A$8="green"))

returned 1 not 2. Any other suggestions would be appreciated.


The count should be 2. What happens if we test the following?

=SUMPRODUCT(--(TRIM($A$1:$A$7)="apple"),--(TRIM($A$2:$A$8)="green"))
 
Upvote 0
Thanks but both
=COUNTIFS(A1:A8,"Apple",A2:A9,"Green")
and

=SUMPRODUCT(--($A$1:$A$7="apple"),--($A$2:$A$8="green"))

returned 1 not 2. Any other suggestions would be appreciated.


My suggestion returned 2 here using the data you provided.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top