# Using IF AND with the COUNT function

#### BobbyB88

##### New Member
Hi,

I am currently trying to do a COUNTIFS on a closed sheet. Checking the forums, I have tried splitting the formula into COUNT(IF(, but as I was counting between two dates I need an IFAND. Can't work out how to calculate it

=COUNT(IF(AND('[DOC.xlsm]New'!\$F\$7:\$F\$2506,">="&\$A\$1,'[DOC.xlsm]New'!\$F\$7:\$F\$2506,"<="&\$B\$1),1))

A1 and B1 are the beginning and end date. It began life as the below formula which worked correctly.

=COUNTIFS('[DOC.xlsm]New'!\$F:\$F,">="&\$A\$1,'[DOC.xlsm]New'!\$F:\$F,"<="&\$B\$1)

Any help, much appreciated

Thanks

Rob

### Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

#### Jonmo1

##### MrExcel MVP
Welcome to the board.

So the issue is that countifs doesn't work on a closed book right?
Try a sumproduct equivelent.

=SUMPRODUCT(--('[DOC.xlsm]New'!\$F:\$F>=\$A\$1),--('[DOC.xlsm]New'!\$F:\$F<=\$B\$1))

Though I highly recommend NOT using entire column references in sumproduct.
Countif was smart enough to only parse through the actual used range, sumproduct will actually parse every single row.
That creates ALOT of unnecessary calculations on empty rows.
So it's best to define start/end rows in the ranges.
I use the 10% rule of thumb, like in construction.
Use 10% more rows than you think you'll need.
So if your dataset is normally around 5000 rows, use 5500

=SUMPRODUCT(--('[DOC.xlsm]New'!\$F\$1:\$F\$5500>=\$A\$1),--('[DOC.xlsm]New'!\$F\$1:\$F%5500<=\$B\$1))

#### BobbyB88

##### New Member
Hi,

That was spot on, thankyou. I am trying to understand now how to SUM that product for a further calculation, but seem to be messing up somewhere. Could you take a quick look please?

=SUMPRODUCT(--('[DOC.xlsm]New'!\$F\$7:\$F\$2506>=\$A\$1),--('[DOC.xlsm]New'!\$F\$7:\$F\$2506<=\$B\$1),'[DOC.xlsm]New'!\$AA\$7:\$AA\$2506)

The intended sum is column AA, but I cannot see where I have gone wrong

Cheers

Rob

#### Jonmo1

##### MrExcel MVP
That apears to be the correct syntax to sum based on the criteria.

did this give the correct COUNT ?
=SUMPRODUCT(--('[DOC.xlsm]New'!\$F\$7:\$F\$2506>=\$A\$1),--('[DOC.xlsm]New'!\$F\$7:\$F\$2506<=\$B\$1))

If that produces the correct 'Count' but the formula you posted doesn't give the correct sum, that would mean
Some or All of the values in Column AA are not really numbers (at least the ones corresponding to the True results of the criteria).

Does this give the correct result (granted it won't work on the closed book, this is just troubleshooting)
=SUMIFS('[DOC.xlsm]New'!\$AA\$7:\$AA\$2506,'[DOC.xlsm]New'!\$F\$7:\$F\$2506,">="&\$A\$1,'[DOC.xlsm]New'!\$F\$7:\$F\$2506,"<="&\$B\$1)

#### BobbyB88

##### New Member
Sorry yes, that was my fault, a #N/A outside of the date range that I hadn't spotted.

Have a great day

Rob

#### Jonmo1

##### MrExcel MVP
You're welcome.

Replies
1
Views
205
Replies
5
Views
350
Replies
0
Views
58
Replies
5
Views
752
Replies
0
Views
70

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,163,707
Messages
5,833,242
Members
430,199
Latest member
Petty queen

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