[VBA/Formula] Countifs where Criteria is one of comma separated value in cell?

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
788
Office Version
  1. 2010
Platform
  1. Windows
Let's say I have a column which can have any single letter or number, and then I want to countif where all characters are "1, 2, 4" or "E, F" or "L, U, V, K"

How can I do this? The cell with the criteria in is in column A and the range is in sheet "LYTemp" range "W2:W & Lastrow"

Thanks.
 
You should be able to do it by separating your conditions using comma - in general:
=SUMPRODUCT(1st condition,2nd condition,3rd condition)

In your case it would be something like that:
=SUMPRODUCT(your ISNUMBER formula, --($U$1:$U$14>43466), --($U$1:$U$14<43496))
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You should be able to do it by separating your conditions using comma - in general:
=SUMPRODUCT(1st condition,2nd condition,3rd condition)

In your case it would be something like that:
=SUMPRODUCT(your ISNUMBER formula, --($U$1:$U$14>43466), --($U$1:$U$14<43496))

Hey,

I have this so far:

VBA Code:
=SUMPRODUCT((RPR!$J$2:$J$14794)*(--ISNUMBER(FIND(RPR!$W$2:$W$14794,A3)))*(RPR!$U$2:$U$14794>=Home!A20)*(RPR!$U$2:$U$14794<=Home!A21))


It's giving me £630,675 where I would expect £215,830

In Home cells A20 and A21 I have 01/01/2019 and 31/01/2019 respectively.

Cheers

EDIT: I've just found out, £630,675 is the total revenue for the month across all product lines, it's not looking at revenue for 1, 2 4 etc and for the other entries (3,6 | E,F etc) it's showing 0.

So it looks like it's not going into the product lines...
 
Upvote 0
Unfortunately, it's hard to say what is wrong without the screenshots of your dataset. Your current formula works fine for me - see below:

Here's RPR tab - dates between 1/1/19 and 31/1/19 are highlighted with a blue colour. My condition (1, 2, 4) means that only rows 7 & 8 will be ultimately taken into account:

1578759982778.png


...and here's the Home tab - with your dates in cells A20 & A21, criteria in cell A3 (1, 2, 4) and your formula in cell B1 returning the correct result (6 + 7 = 13):

1578760036100.png
 
Upvote 0
Yeah I must've had something funny going on.... This totally works, thanks again for all your help.

Old Formula:
VBA Code:
=SUMPRODUCT((RPR!$J$2:$J$14794)*(--ISNUMBER(FIND(RPR!$W$2:$W$14794,A3)))*(RPR!$U$2:$U$14794>=Home!$A$20)*(RPR!$U$2:$U$14794<=Home!$A$21))

New Formula:
VBA Code:
=SUMPRODUCT((RPR!$J$2:$J$14794)*(--ISNUMBER(FIND(RPR!$AD$2:$AD$14794,Home!A3)))*(RPR!$U$2:$U$14794>=Home!A20)*((RPR!$U$2:$U$14794<=Home!A21)))

Ah, looks like I was missing the "Home" designation on some tags, which was probably looking in the wrong sheet.
 
Upvote 0
Here's one of the resulting formulas, transposed to VBA, where I sum the pax against a sum of the people who made their first booking, across two databases... It got a bit ridiculous...

VBA Code:
Range("U3:U10").FormulaR1C1 = "=(SUMPRODUCT(('[" & bd2.Parent.Name & "]Booking Database'!R2C3:R" & LastrowBD2 & "C3)*(--ISNUMBER(FIND('[" & bd2.Parent.Name & "]Booking Database'!R2C30:R" & LastrowBD2 & "C30,Home!RC[-6])))*('[" & bd2.Parent.Name & "]Booking Database'!R2C21:R" & LastrowBD2 & "C21>=" & TMRS & ")*('[" & bd2.Parent.Name & "]Booking Database'!R2C21:R" & LastrowBD2 & "C21<=" & TMRE & ")*('[" & bd2.Parent.Name & "]Booking Database'!R2C8:R" & LastrowBD2 & "C8=""Y""))+SUMPRODUCT(('[" & bd.Parent.Name & "]Booking Database'!R2C3:R" & LastrowBD & "C3)*(--ISNUMBER(FIND('[" & bd.Parent.Name & "]Booking Database'!R2C30:R" & LastrowBD & "C30,Home!RC[-6])))*('[" & bd.Parent.Name & "]Booking Database'!R2C21:R" & LastrowBD & "C21>=" & TMRS & ")*('[" & bd.Parent.Name & "]Booking Database'!R2C21:R" & LastrowBD & "C21<=" & TMRE & ")*('[" & bd.Parent.Name & "]Booking Database'!R2C8:R" & LastrowBD & "C8=""Y"")))/RC17"
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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