# SUMPRODUCT to count BETWEEN numbers and only VISIBLE cells

#### Gilberto Fernandez

##### New Member
Hello,

Im currently using this formula to count cells that match the contents of another cell. It works perfectly only counting visible cells.

=SUMPRODUCT(--(\$A\$12:\$A\$50000=A50003),(SUBTOTAL(103,OFFSET(\$A\$12,ROW(\$A\$12:\$A\$50000)-MIN(ROW(\$A\$12:\$A\$50000)),,))))

I need another formula to count cells with the condition that its value lies between the values of two reference cells. I tried to modify the above formula but its not working.

=SUMPRODUCT(--(\$A\$12:\$A\$50000>G50003),(\$A\$12:\$A\$50000<=H50003),(SUBTOTAL(103,OFFSET(\$A\$12,ROW(\$A\$12:\$A\$50000)-MIN(ROW(\$A\$12:\$A\$50000)),,))))

Any ideas?
Thanks,
Gilberto

#### Domenic

##### MrExcel MVP
Try...

=SUMPRODUCT(--(\$A\$12:\$A\$50000>G50003),--(\$A\$12:\$A\$50000<=H50003),SUBTOTAL(103,OFFSET(\$A\$12:\$A\$50000,ROW(\$A\$12:\$A\$50000)-ROW(\$A\$12),0,1)))

#### Gilberto Fernandez

##### New Member
That was a quick reply thank you very much.

The formula returns the TOTAL count of all the visible cells (its NOT counting ONLY the the cells which value is BETWEEN the two reference cells).

#### Gilberto Fernandez

##### New Member

IT WORKS PERFECTLY, thanks.

1,081,726
Messages
5,360,906
Members
400,602
Latest member
newaqua

### This Week's Hot Topics

• VBA (Userform)
Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
• List box that changes fill color
Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
• Remove duplicates and retain one. Cross-linked cases
Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
• VBA Copy and Paste With Duplicates
Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
• Macro
is it possible for a macro to run if the active cell value is different to the value above it
• IF DATE and TIME
I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...