Can we have a formula or a VBA code for counting number of next cells based on criteria.
For instance if we have a list
A
A
B
A
C
and we would like to count number of A's after A (the criteria), so in this case, it would be 1
If you just want to know the number of times A is followed by A then you can use a formula like this
=COUNTIFS(A1:A5,"A",A2:A6,"A")
Assuming your data is in A1:A5
This will also allow you to find out how many times A is followed by B or any other combination by changing the criteria
Use SUMPRODUCT():
=SUMPRODUCT(($A$1:$A$5="A")*($A$2:$A$6=$A$1:$A$5))
The simplest possible solution that I can think for this problem is
=IF(A2<>A1,0,INDEX(MATCH(FALSE,A2:A100=A1,0),1,1)-1)
Related
I have a spreadsheet with Company Name and Serial Number columns. The serial number column values are in range e.g. 1001-2000. How do I look up company name from a specific serial number value? See this screenshot for example.
Column B can be split into two columns if needed though it is preferable to have single column.
I tried this example but got a #Spill! error
Or, using Lookup+Imreal function
In E2, enter formula:
=LOOKUP(D2,IMREAL(B2:B5&"i"),A2:A5)
Be careful with this... It is a crude hack.
=IF(D2<=1000,A2,INDEX(A:A,MATCH(D2+1&"-"&D2,B:B,1)))
in the special case of the ranges all ending at a multiple of 1000 and each band being essentially 1000 units you could go with the special case formula of
=INDEX($A$2:$A$5,INT(($D2-1)/1000)+1)
Note that you don't actually use the info in column B for this option. It is based purely on the pattern to the range breakdown
if you want to restrict it to values between 1 and 4000 you could wrap it in an if statement that checks for that.
=IF(AND(D2>=1,D2<=4000),INDEX($A$2:$A$5,INT(($D2-1)/1000)+1),"SN out of range")
I am having difficulties combining Vlookup value with count.
As you can see here, CPR is a unique code for every employee and next to it is the type of mistakes that specific employee did.
In this sheet, i want to count the number of mistakes done by that specific employee from the first sheet which mean the code should only count the cells that only contain value.
Thank you.
You can use following formula:
=SUMPRODUCT(($A$1:$A$10=E2)*NOT(ISBLANK($B$1:$B$10)))
I think you want to use Excel's countif function. I don't think vlookup is helpful here.
For example, if you write =countif(G4:G999, 8345) it will count how many times the number 8345 occurs in that range of cells.
You could use:
=COUNTIF(Jan!G:G,Sheet13!D1)
The above formula count how many times the value in Sheet13!D1 appears in Jan!G:G
I'm working in Excel 2013. I've had a quick google for this, but I think my terminology might be wrong as I'm not finding a response that solves my exact problem.
I have a column of concatenated healthcare-related outcomes, such as:
"999 Emergency Ambulance By Co-op Admit Accident & Emergency! Admitted To Hospital"
"Advice Only"
"Admit to hospital"
"Medication prescribed"
I want to enter one formula in one cell that counts the records that EITHER contain "999" "Admit" OR "A&E" OR "Admission" for the ENTIRE column.
I don't want to have another column performing this count, I know the following works:
=IF(ISNUMBER(SEARCH("999",K2)),1,IF(ISNUMBER(SEARCH("ADMIT",K2)),1,IF(ISNUMBER(SEARCH("ADMISSION",K2)),1,0)))
But the formula I would need would replace the sum of the column that contained the above formula, negating the need for an extra column.
What I'm struggling with is that the other solutions I've seen would check the column for each condition and you'd end up with cells counted twice. As you can see in the above, some cells will contain "999" AND "Admit".
Apologies if this is a simple question!
Thanks in advance.
You can use this formula:
=SUMPRODUCT(1*((NOT(ISERROR(SEARCH("999";A1:A4)))+NOT(ISERROR(SEARCH("Admit";A1:A4)))+NOT(ISERROR(SEARCH("Admission";A1:A4))))>0))
Or, as in your example, use Isnumber instead of NOT(ISERROR(
Depending on your regional settings you may need to replace field separator ";" by ","
You can use MMULT here to avoid some repetition, i.e.
=SUMPRODUCT((MMULT(ISNUMBER(SEARCH({999,"Admit","A&E","Admission"},K2:K100))+0,{1;1;1;1})>0)+0)
Assumes data in the range K2:K100 - change as required
Note that there are 4 1s in {1;1;1;1} to match the 4 search terms - if you increase the number of search terms you need to increase the numbers of 1s
My searches for answers have been limited by my lack of knowledge of the appropriate terminology. My goal is to count the number of times a specific username appears in one column AND the number 1 appears in another column for that user. I attempted to use COUNTIF, but it doesn't seem to format for that purpose.
What I'm needing is to count the number of instances "username" appears in column K when "1" appears in column Q.
If you have =COUNTIFS (you don't mention which version of Excel) please try, in Row1 and copied down to suit:
=COUNTIFS(Q:Q,1,K:K,K1)
there may be better ways (eg a PivotTable, an array formula or =SUMPRODUCT) but this could be one of the simplest.
Alternatively of course just filter and read the count in the bottom left-hand corner of your screen.
Showing COUNTIFS, SUMPRODUCT, PivotTable and filter options:
In this special case, because one of your criteria is 1, you might also use SUMIFS.
Because the data happens to start with a list of unique Users in order the COUNTIFS version in Row2 (adjusted to K2 from K1) entered with Ctrl+Shift+Enter and copied down to Row 6 will show a result similar to that in the PT.
I have two excel sheets where I need to match three values to return a fourth. The similar columns are month, agent, and subdomain. The fourth column is called difference.
Concatenate would work, as per #MakeCents suggestion, but if you don't want a helper column, SUMPRODUCT would work.
example:
=SUMPRODUCT(--(A2:A12="d"),--(B2:B12="S"),--(C2:C12="Apr"),D2:D12)
would search range A2:A12 for "d", B2:B12 for "S" and C2:C12 for "Apr", and return the value fom D2:D12 that corresponds to where all 3 are true. If multiple lines match, it will add the value in D2:D12 for all matching rows.
The -- is used to change the True/False results into 0 and 1 for use in multiplication
Limitations of SUMPRODUCT
Recommended to specify the range explicitly; it will be slower with just
column references
(A1:A4000 is ok, A:A is not)
It will return an error if any of the values are errors
It will return numeric results only - text is evaluated as Zero
Although I believe #MakeCents comment / suggestion on how to do this is the way I would go since it is the simplest, you could accomplish this a different way (MUCH more processor-intensive, though) using the Index() and Match() functions and Array formulas.
For example, suppose your 3 columns of data you're looking to match against are columns A-C and you're looking to return the matching value from column D in Sheet1
Now, the 3 values you're looking to have matched are in cells A1, B1 & C1 of Sheet2, you could use the following formula:
=INDEX(Sheet1!D:D,MATCH(1,(Sheet1!A:A=A1)*(Sheet1!B:B=B1)*(Sheet1!C:C=C1),0))
And ENTER IT AS AN ARRAY FORMULA by pressing Ctrl + Shift + Enter
Hope this helps!
You are looking for a Lookup with multiple criteria.
One of the most robust options is
=INDEX(D:D,SUMPRODUCT(--(A:A="d"),--(B:B="S"),--(C:C="Apr"),ROW(D:D)),0)
It does not need to be entered as an array formula.
Taken from [1] (blogs.office.com).
See also this very complete answer, which summarizes this and other options for performing a lookup with multiple criteria.
PS1: Note that I used references to full columns, as per this.
PS2: This can be considered an enhancement to the solution by Sean for the case when the output column does not contain numbers.
References
[1] This post is written by JP Pinto, the winner of the Great White Shark Award given for the best article written about VLOOKUP during VLOOKUP Week.
Try this
=IF(A4=Data!$A$4:$A$741,IF(B4=Data!$B$4:$B$741,"Hai"))