# Count in a range how many meet two conditions across a row, VBA

#### Technowolf

##### Board Regular
Okay, I don't think this is that hard but I'm not sure exactly how to do it.
I want it to count how many times something meets two conditions across a row. For example, I want to know how many times A is 1F and B is 20, but only if they're on the same row together (as in, don't count 1D & 20 or 1F & 10, etc). I want it to check how many times that happens for the whole set of data. And show the results in cell C1.

 A B C 1F 20 1D 20 1F 10 1D 20 1F 20 1F 10 1D 20 1D 10 1D 20 1F 20

<tbody>
</tbody>

Suggestions?

Last edited:

### Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try (Excel 2007 or higher)

=COUNTIFS(A:A,"1F",B:B,20)

M.

Okay, yeah that I started with a countifs but didn't know if it would pair rows. I can work with that. Okay, followup question.
(because I need to use this in a macro)
How do I make a formula work with quotes in a macro?

Code:
``Range("C2").Formula = "[COLOR=#333333]COUNTIFS(A:A,"1F",B:B,20)[/COLOR]"``

But the "s around the "1F" screw up the macro. How do I make that work?

Ahhh I figured it out. Have to double "".

Code:
``[COLOR=#333333]Range("C2").Formula = "[/COLOR][COLOR=#333333][COLOR=#333333]COUNTIFS(A:A,""1F"",B:B,20)[/COLOR][/COLOR][COLOR=#333333]"[/COLOR]``

Replies
3
Views
896
Replies
4
Views
238
Replies
9
Views
598
Replies
7
Views
957
Replies
4
Views
378

1,196,391
Messages
6,015,006
Members
441,865
Latest member
Enragedpanda

### 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