Countif function not acting how I would expect - excel

So I have an excel function where I want to check to see if a string contains any of the strings mentioned, if it does, simply add 1 to the total, here's what I have:
=COUNTIF(C2:F2, "*offline")+COUNTIF(C2:F2, "*Expired")+COUNTIF(C2:F2, "*login")+COUNTIF(C2:F2, "*log in")
So for example if C2 says "login" D2 says "offline" , this function would only show "1".

Examples using just one Countif
If you want to count 1 then here is an example
=IF(SUM(COUNTIF(C2:F2, {"*offline","*Expired","*login","*log in"}))>0,1,0)
If you want to count all instances then change the above formula to
=SUM(COUNTIF(C2:F2, {"*offline","*Expired","*login","*log in"}))
Screenshot

So, you don't really want a count, you just want to know if any of those cells have one of the values you're looking for?
Surround your function in an if statement and print 1 if it has a count at all.
=IF(COUNTIF(C2:F2, "*offline")+COUNTIF(C2:F2, "*Expired")+COUNTIF(C2:F2, "*login")+COUNTIF(C2:F2, "*log in"),1,0)

Related

How to extract specific text from a sentence in Excel?

I have a database that exports data like this:
How can I get for instance, the Net Rentable Area with the values needed:
E.G.
Net Rentable Area
I tried the TextSplit function but I got a spill.
Please let me know what can be done, thanks!
Also it would be nice to see it working in something such as the Asking Rate, which has a different format.
In cell C2 you can put the following formula:
=1*TEXTSPLIT(TEXTAFTER(A2, B2&" ")," ")
Note: Multiplying by 1 ensures the result will be a number instead of a text.
and here is the output:
If all tokens to find are all words (not interpreted as numbers), then you can use the following without requiring to specify the token to find:
=LET(split, 1*TEXTSPLIT(A2," "), FILTER(split, ISNUMBER(split)))
Under this assumption you can even have the corresponding array version as follow:
=LET(rng, A2:A100, input, FILTER(rng, rng <>""), IFERROR(DROP(REDUCE(0, input,
LAMBDA(acc,text, LET(split, 1*TEXTSPLIT(text," "),
nums, FILTER(split, ISNUMBER(split),""), VSTACK(acc, nums)))),1),"")
)
Note: It uses the trick for creating multiple rows using VSTACK within REDUCE. An idea suggested by #JvdV from this answer. It assumes A1 has the title of the column, if not you can use A:A instead.

COUNTIFS counting double amount of values

I've got the following formula that works correctly
=SUM(COUNTIFS(MachineData!N:N,{"*Arlington*","*RenewNorfolk*"}, MachineData!$X:$X,"Y"))
but now if I try to do the same but with "not arlington or not renewnorforlk" I get the wrong answer (it counts double the amount of values that I want to count)
=SUM(COUNTIFS(MachineData!N:N,{"<>*Arlington*","<>*RenewNorfolk*"}, MachineData!$X:$X,"Y"))
what is happening here?
Your first statement is equivalent to
=COUNTIFS(MachineData!N:N,"*Arlington*", MachineData!$X:$X,"Y") + COUNTIFS(MachineData!N:N,"*RenewNorfolk*", MachineData!$X:$X,"Y")
where the array constant is manually split into it two constituent parts.
If you try this with the second statement
=COUNTIFS(MachineData!N:N,"<>*Arlington*", MachineData!$X:$X,"Y") + COUNTIFS(MachineData!N:N,"<>*RenewNorfolk*", MachineData!$X:$X,"Y")
we can see that anything that isn't either Arlington or RenewNorfolk gets counted by both COUNTIFS statements, which isn't what we want the result to be.
The simplest solution is to use
=COUNTIFS(MachineData!N:N,"<>*Arlington*", MachineData!N:N,"<>*RenewNorfolk*", MachineData!$X:$X,"Y")
which requires all the criteria to be met for a data item to be counted.

Excel If statement needs to show blanks while being nested

I am writing a formula to see cells that are blank along with see the cells that have a numeric value such as 0,10,-100 etc.
I have the following code that works but if the cell is blank it shows "0" and I need that to show blank. I should note that I am using offsets to make it easier to duplicate the data into other rows and just use REPLACE to speed up the process.
=IF(B1=DATEVALUE("7/3/2020"),OFFSET('CEDAR RAPIDS'!R4,0,0),
IF(B1=DATEVALUE("7/10/2020"),OFFSET('CEDAR RAPIDS'!R25,0,0),
IF(B1=DATEVALUE("7/17/2020"),OFFSET('CEDAR RAPIDS'!R47,0,0),
IF(B1=DATEVALUE("7/24/2020"),OFFSET('CEDAR RAPIDS'!R69,0,0),
IF(B1=DATEVALUE("7/31/2020"),OFFSET('CEDAR RAPIDS'!R91,0,0),
IF(B1=DATEVALUE("8/7/2020"),OFFSET('CEDAR RAPIDS'!R112,0,0),
IF(B1=DATEVALUE("8/14/2020"),OFFSET('CEDAR RAPIDS'!R133,0,0),
IF(B1=DATEVALUE("8/21/2020"),OFFSET('CEDAR RAPIDS'!R154,0,0),
IF(B1=DATEVALUE("8/28/2020"),OFFSET('CEDAR RAPIDS'!R174,0,0),
IF(B1=DATEVALUE("9/4/2020"),OFFSET('CEDAR RAPIDS'!R195,0,0),
IF(B1=DATEVALUE("9/11/2020"),OFFSET('CEDAR RAPIDS'!R215,0,0),
IF(B1=DATEVALUE("9/18/2020"),OFFSET('CEDAR RAPIDS'!R235,0,0),
IF(B1=DATEVALUE("9/25/2020"),OFFSET('CEDAR RAPIDS'!R255,0,0),
IF(B1=DATEVALUE("10/02/2020"),OFFSET('CEDAR RAPIDS'!R275,0,0),
IF(B1=DATEVALUE("10/9/2020"),OFFSET('CEDAR RAPIDS'!R295,0,0),
IF(B1=DATEVALUE("10/16/2020"),OFFSET('CEDAR RAPIDS'!R314,0,0),
IF(B1=DATEVALUE("10/23/2020"),OFFSET('CEDAR RAPIDS'!R334,0,0),
IF(B1=DATEVALUE("10/30/2020"),OFFSET('CEDAR RAPIDS'!R354,0,0),
IF(B1=DATEVALUE("11/6/2020"),OFFSET('CEDAR RAPIDS'!R374,0,0),
IF(B1=DATEVALUE("11/13/2020"),OFFSET('CEDAR RAPIDS'!R394,0,0),
IF(B1=DATEVALUE("11/20/2020"),OFFSET('CEDAR RAPIDS'!R414,0,0),
IF(B1=DATEVALUE("11/27/2020"),OFFSET('CEDAR RAPIDS'!R434,0,0),
IF(B1=DATEVALUE("12/4/2020"),OFFSET('CEDAR RAPIDS'!R454,0,0),
IF(B1=DATEVALUE("12/11/2020"),OFFSET('CEDAR RAPIDS'!R474,0,0)))))))))))))))))))))))))
I found this code below works correctly but I cannot seem to nest it like the above without errors.
=IF(B1=DATEVALUE("7/3/2020"),IF(ISBLANK('CEDAR RAPIDS'!F4),"",OFFSET('CEDAR RAPIDS'!F4,0,0)))
Format the result of the cells with a custom number format that suppresses zeroes, for example
0;-0;;#
By the way, if you want to check if the result of the OFFSET() is zero, then you need to check the result of the OFFSET(), not the anchor of the OFFSET().
There is bound to be a better formula for this scenario than this nested monster with Offset. Just ask.

excel nested vlookup function using formats and NA Arguments

I placed an example below, of which I don't necessarily 'need' to work, but I don't like that I can't get it to work. I've attempted to use the ISNA function, but am having little success since I
=IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Additional Credit… Research","No Credit Exists")))
I really would like to have a response to each formula, am I using the wrong functions or the wrong format?
To avoid repeating the VLOOKUP function multiple times you can use SIGN and CHOOSE in this scenario like this
=CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research")
If you add the VLOOKUP result to J3 you will get a negative number, zero or a positive number, SIGN function will return -1, 0 or 1 respectively for those and then adding 2 gives 1, 2 or 3 so we can use CHOOSE function to convert 1,2 or 3 to the relevant text value
That formula still gives #N/A error if H3 isn't found in Credit!H:H so to avoid that use IFERROR function (assumes Excel 207 or later), so final version becomes:
=IFERROR(CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research"),"No credit exists")
perhaps
=IF(ISNA(MATCH(H3,Credit!H:H,0)),"No Credit Exists",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research","Additional Credit… Research")))
the MATCH part looks for the value H3 in Credit!H:H and if it isn't there the ISNA handles the resulting error and returns "No credit exists"; the rest is basically just a tweak of the original formula

Return a row number that matches multiple criteria in vbs excel

I need to be able to search my whole table for a row that matches multiple criteria. We use a program that outputs data in the form of a .csv file. It has rows that separate sets of data, each of these headers don't have any columns that are unique in of them self but if i searched the table for multiple values i should be able to pinpoint each header row. I know i can use Application.WorksheetFunction.Match to return a row on a single criteria but i need to search on two three or four criteria.
In pseudo-code it would be something like this:
Return row number were column A = bill & column B = Woods & column C = some other data
We need to work with arrays:
There are 2 kinds of arrays:
numeric {1,0,1,1,1,0,0,1}
boolean {TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE}
to convert between them we can use:
MATCH function
MATCH(1,{1,0,1,1,1,0,0,1},0) -> will result {TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE}
simple multiplication
{TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE}*{TRUE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE} -> will result {1,0,1,1,1,0,0,1}
you can can check an array in the match function, entering it like in the picture below, be warned that MATCH function WILL TREAT AN ARRAY AS AN "OR" FUNCTION (one match will result in true
ie:
MATCH(1,{1,0,1,1,1,0,0,1},0)=TRUE
, YOU MUST CTR+SHIFT+ENTER !!! FOR IT TO GIVE AN ARRAY BACK!!!
in the example below i show that i want to sum the hours of all the employees except the admin per case
we have 2 options, the long simple way, the complicated fast way:
long simple way
D2=SUMPRODUCT(C2:C9,(A2=A2:A9)*("admin"<>B2:B9)) <<- SUMPRODUCT makes a multiplication
basically A1={2,3,11,3,2,4,5,6}*{0,1,1,0,0,0,0,0} (IT MUST BE A NUMERIC ARRAY TO THE RIGHT IN SUMPRODUCT!!!)
ie: A1=2*0+3*1+11*1+3*0+2*0+4*0+5*0+6*0
this causes a problem because if you drag the cell to autocomplete the rest of the cells, it will edit the lower and higher values of
ie: D9=SUMPRODUCT(C9:C16,(A9=A9:A16)*("admin"<>B9:B16)), which is out of bounds
same as the above if you have a table and want to view the results in a diferent order
the fast complicated way
D3=SUMPRODUCT(INDIRECT("c2:c9"),(A3=INDIRECT("a2:a9"))*("admin"<>INDIRECT("b2:b9")))
it's the same, except that INDIRECT was used on the cells that we want not be modified when autocompleting or table reorderings
be warned that INDIRECT sometimes give VOLATILE ERROR,i recommend not using it on a single cell or using it only once in an array
f* c* i cant post pictures :(
table is:
case emplyee hours totalHoursPerCaseWithoutAdmin
1 admin 2 14
1 him 3 14
1 her 11 14
2 him 3 5
2 her 2 5
3 you 4 10
3 admin 5 10
3 her 6 10
and for the functions to check the arrays, open the insert function button (it looks like and fx) then doubleclick MATCH and then if you enter inside the Lookup_array a value like
A2=A2:A9 for our example it will give {TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE} that is because only the first 3 lines are from case=1
Something like this?
Assuming that you data in in A1:C20
I am looking for "Bill" in A, "Woods" in B and "some other data" in C
Change as applicable
=IF(INDEX(A1:A20,MATCH("Bill",A1:A20,0),1)="Bill",IF(INDEX(B1:B20,MATCH("Woods",B1:B20,0),1)="Woods",IF(INDEX(C1:C20,MATCH("some other data",C1:C20,0),1)="some other data",MATCH("Bill",A1:A20,0),"Not Found")))
SNAPSHOT
I would use this array* formula (for three criteria):
=MATCH(1,((Range1=Criterion1)*(Range2=Criterion2)*(Range3=Criterion3)),0)
*commit with Ctrl+Shift+Enter

Resources