Dynamically Adding Parameters to CountIfs in VBA - excel

I'd like to use countifs in VBA without knowing the amount of criteria/ranges. So in the example below, my script would see that there were 2 criterias, and apply 2 sets of criteria/ranges.
How do I do this in VBA, I can do everything apart from put it in the countifs formula. I tried putting it in a string/variant, ie: Application.Worksheetfunctions.Countifs(stringvariable) but it has not worked, I understand why it has not worked but I can't find a way to do this.
Thanks in Advance for your help.

1) Create the formula as a string
2) Use application.evaluate(var) to get the result

Related

lookup with multiple conditions and for rows

Hello sages from StackOverflow,
I'm in search of a formula that can relate 3 diferent conditions, I tried using some IF statemets with the TEXTJOIN formula but I find myself lost in the way,
I got a data base just like this (image below), just a much bigger one, I want to search for a key like MCAA01 and obtain the doc's that have in front of it a "NO" all in one cell, like if you use the formula TEXTJOIN("/",...
My problem is that I cannot find a way to relate the whole column of the doc's with the key,
I tried something like TEXTJOIN("/",TRUE,IF(2ndIMAGE!A2=1stIMAGE!B1,IF(B2="no",1stIMAGE!A2,""),""))
This does give a result but it's just 1 thing, not whole answer
please sages of StackOverflow, you're my only hope. Thank you!
You need FILTER() then TEXTJOIN().
=TEXTJOIN("/",TRUE,FILTER($A$2:$A$4,FILTER($B$2:$H$4,$B$1:$H$1=$B8)="No",""))
If your version of excel supports LAMBDA() function then you can try below formula and you do not need to drag the formula to each cell. It will spill results automatically.
=BYROW(B8:B14,LAMBDA(a,TEXTJOIN("/",TRUE,FILTER(A2:A4,FILTER(B2:H4,B1:H1=a)="No",""))))

Extract Specific Value from Cell in Excel

I have a work dilemma. I have some cells, too many to manual work, that have some combination of the below:
"grievance 01-11 filed 09/19/02"
I am hoping to get only the "01-11" or whatever combination of xx-xx from the cell. I have used =LEFT(R102,FIND("-",R102)-1), but it gives me everything before/after the dash.
Thank y'all for any assistance!
Use SEARCH:
=MID(R102,SEARCH("??-??",R102),5)

How can I use COUNTIFS for multiple criteria?

I want to be able to use the COUNTIFS formula for multiple criteria.
For example:
1,Banana
2,Orange
1,Banana
2,Orange
I want to use COUNTIFS to count how many occurrences of 1 is associated with banana and how many times 2 is associated with orange.
I'm thinking of =COUNTIFS(A:A,1,B:B,"Banana")+=COUNTIFS(A:A,2,B:B,"Orange")
This would supposedly equal 4, but I know that formula is wrong and I don't know how to format it.
If this is not possible, then I'd have to use two of the same formulas and add them together, but I'm looking for a better way and just use one formula.
How do I go about this problem, any help would be greatly appreciated.
Thank you.
EDIT: =COUNTIFS(A:A,1,B:B,"Banana",A:A,2,B:B,"Orange") returns 0 for some reason, why is that?
You can try SUMPRODUCT function instead:
=SUMPRODUCT(((B:B="Orange")+(B:B="Banana"))*(A:A=1))
To add additional criteria value, you need to add it to the rest, for example - adding Apples criteria:
=SUMPRODUCT(((B:B="Orange")+(B:B="Banana")+(B:B="Apple"))*(A:A=1))
Similar logic needs to be used to add another criteria range, for example:
=SUMPRODUCT(((B:B="Orange")+(B:B="Banana"))(A:A=1)(C:C="X"))
Hope it helped.
EDIT: Just saw question adjustment. In that case you should use following logic:
=SUMPRODUCT((B:B="Orange")(A:A=1)+(B:B="Banana")(A:A=2))
your formula should be
=COUNTIFS(A:A,1,B:B,"Banana")+COUNTIFS(A:A,2,B:B,"Orange")

Excel - SUMIFS for multiple columns

I need to sum the values of several columns, if other cells in the same row match a predefined criteria. The working formula for only 3 columns is the following:
=SUM(SUMIFS(‘Sheet1'!W:W; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!X:X; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!Y:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4"))
I will need to use the formula for several cells (and sum more than 10 columns per time) and I will need to change the columns manually, so I need the same formula in the following way:
=SUMIFS(‘Sheet1'!W:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4")
,but currently this formula leads to a "#VALUE!" error. The reason for that is (I assume) the use of multiple columns "W:Y"
Can you suggest a workaround?
I would suggest to use SUMPRODUCT rather than SUMIFS. You can build something like that :
=SUMPRODUCT((B1:B1048575="Sales")*(C1:C1048575>=4)*(W1:Y1048575))
The downside of SUMPRODUCT is that you can't use a whole column (for example you cannot write SUMPRODUCT((B:B="Sales"...)), this would generate an error).
Hope this helps.
I suggest you add a column with the sum('sheet1'!W:Y) and then use sumifs on this columns. It is a two step way but it will give the result you expect
Here's what I have :)
=SUM(SUMIFS('WTD Raw'!R:R,'WTD Raw'!E:E,"Kindle-Customer Care",'WTD
Raw'!J:J,"Week27",'WTD Raw'!H:H,'PassRate | July'!G8) + SUMIFS('WTD
Raw'!R:R,'WTD
Raw'!E:E,"Kindle-Technical Support",'WTD Raw'!J:J,"Week27",'WTD
Raw'!H:H,'PassRate | July'!G8))
Instead of using ";" use the Mathematical Operators for it to work.

Enhanced VLOOKUP formula

I have the following sheet structure:
What I need to find out is, whether code 8101-1101 contains any Matching Projects (in our case 9500-1100). I have tried VLOOKUP formula, however that only works if the matching project is set to the very first item. If matching project exists only somewhere in the middle, then the formula fails. I have also tried SUMIF yet with no luck.
What formula do I need to use, to check this particular example?
As we discussed in the comments, the easiest way to accomplish what you're looking to do would be using the COUNTIFS() function.
Given your example, your final formula would be as follows:
=COUNTIFS(B:B,B2,I:I,"<>")
Good luck and glad it ended up working for you!!

Resources