Excel: Count sum of cells along a row until a value is found - excel

Picture 50 rows that all have a number "4" in it.
However in each row there are 26 columns (A-Z) and the 4 is placed on a different letter in each row.
I need a count of finding the "4" in each row (i.e. if it's "E" that the "4" sits in, the count should be "5".
the 1 should be counted as a 5 because the 4 is 5 cells along

Without seeing your column headings, I think you can just use the MATCH function.
=MATCH(4,A1:I1)
Result
You just need to adapt it to your range.

Related

Move the value of all cells in a column to their corresponding excel row number

Let's say i have the below list of Whole numbers in Column A. If you observe the list of numbers, you will see that number "5" and 6 is missing.
A
3
2
4
1
7
8
what I want to achieve is to place (sort) the numbers on the column such that each cell value will take its position according to excel row numbering. which means:
I should have something like this
1
2
3
4
7
If it's as simple as stated, this should work.
In column B, say:
=IF(COUNTIF(A:A,ROW())>0,ROW(),"")
Note: It does not account for duplicates, or anything complicated really.
Further Note: To clarify, all this does is check if the row that the formula is in, is in column A. If it is, then it returns the current row.

EXCEL: Take the average of a column in row (n-5,n-1) if row n fulfills a condition

There are 50 rows. The first column (A), each row has has a ID number. They are not sorted in any way and should not be either and there are no duplicated ID numbers. When the ID is 0 then consider 4 rows before that row, take the mean value of those values in clumn C between those 4 rows. If it helps It is always the last row that has value ID = 0.
What I have done so far is that I can find the ROW number of the ID = 0 using the following formula:
ROW(INDEX(A3:A53,MATCH(TRUE,INDEX(A3:A53=0,),0)))
Now I don't know how to navigate 4 rows upwards and take the corrosponding values in Column C.
If you use an extra column (say column Z), then paste this code into that column starting on row 4 (NB it won't work properly for the first 3 rows because there are not 4 above to check).
=IF($A4 =0, AVERAGE($C1:$C4), "Not Relevant")
so put that code in Z4, then press ctrl+E to flash fill it downwards.
Hopefully, on each line where the ID is 0, there will be an average of that line and the previous 3 in column Z on that row.
Use:
=AVERAGE(INDEX(A3:A53,MATCH(TRUE,INDEX(A3:A53=0,),0)-5):INDEX(A3:A53,MATCH(TRUE,INDEX(A3:A53=0,),0)-1))

How to add 5 cells consecutively after an interval of 5 cells in a row of 200 cells?

I have a row of 200 cells. I have to add/average first five cells (A:E), and then take a break of 5 cells and then add/average second five cells (K:O) and so on till the end of the row. How can I do this?
I have tried doing it manually. Actually, I can do this manually but wanted to know if I can do this automatically.
I did a test making some faking data like this:
It's just a bunch of numbers from A1 to CB1. 80 numbers in total. 5 first numbers are 1, then next 5 are 2, next 5 numbers are again 1, then next 5 numbers are again 2, and so on.
This mean that there are 80 numbers, where 40 are 1 and 40 are 2. I want to get the average of first five cells (A:E), and then take a break of 5 cells and then average second five cells (K:O) and so on till the end of the row. In other words, I want to get the average of the 40 cells that contains a 1 value, and it should return a 1.
For this, I've used an array formula:
=AVERAGE(IF(VALUE(RIGHT(COLUMN(A1:CB1);1))<6;IF(VALUE(RIGHT(COLUMN(A1:CB1);1))>0;A1:CB1)))
NOTE: Because this is an array formula, it must be inserted pressing ENTER+CTRL+SHIFT instead of
only ENTER, or it won't work!
How this works?
You want to sum/average only values that are in columns where last digit of column number is 1 to 5, this means columns 1,2,3,4,5,11,12,13,14,15,21,22,23,24,25, and so on. So this works this way:
The part that says COLUMN(A1:CB1) will get an array of column numbers.
RIGHT(COLUMN(A1:CB1);1) will get last digit of each column number, but as text
VALUE(RIGHT(COLUMN(A1:CB1);1)) will convert that last digit into a number.
Then with both IFS, we get an array of only those values where last digit of column number is >0 and <6, and we get the average. I get as result of my average 1 and it's true, because the average of 40 times 1 is equal to 1.
Hope this works for you. You can adapt this easily to make it work with 200 cells.
For example:
In A2 put:
=IF(MOD(COLUMN(),10)=1,AVERAGE(INDEX(1:1,,COLUMN()):INDEX(1:1,,COLUMN()+4)),"")
Drag right.
You can use SUMPRODUCT to add the amounts in the columns and divide by 100:
=SUMPRODUCT(--ISEVEN(INT((COLUMN(A1:GR1)-1)/5)),A1:GR1)/100
if you do not always have 200 numbers you can make the 100 more dynamic with another SUMPRODUCT:
=SUMPRODUCT(--ISEVEN(INT((COLUMN(A1:GR1)-1)/5)),A1:GR1)/SUMPRODUCT(ISEVEN(INT((COLUMN(A1:GR1)-1)/5))*(ISNUMBER(A1:GR1)))
this function have CTRL+SHift+Enter and drag this function until your last data IF(OR((RIGHT(COLUMN(A5),1)+0)={1,2,3,4,5}),A5,--FALSE)
You Find The Columns only which end (1,2,3,4,5) , in last. You use Sum function For Add.

Using COUNTIFS for a series of values at once

Working a step higher then COUNTIFS, I appose a challenge to write a formula without VBA code. The basic data is combined from 1000s of rows with:
Column A: rows with values from 1 to 3
Column B: rows with values from 1 to 250.
For this purpose lets say, we are looking at all cells of value "1" in column A, that suit value "5" in column B. To find all matches, we'd use COUNTIFS command.
1 1
2 5
1 5
1 7
1 10
3 45
2 12
1 2
2 1
=COUNTIFS(A1:A9;1;B1:B9;5)
The answer here is 1.
Next thing, the "5" in column B belongs to a group, e.g. group from 1 to 9. What would the best way be, to count all the matches in this example, so that for all "1"'s in column A, we'd have to find all matches with values from 1 to 9 in column B?! In the upper example that would result in "4". The obvious solution is with a series of IF commands, but that's unefficient and it easy to make a mistake, that get's easily overseen.
=COUNTIFS(A1:A9;1;B1:B9;"<="&9)
Works only as the upper limit. If I give the third criteria range and condition as ">="&1 it does not work - returns 0.
Gasper
Where the data is in A1:B9, using a lookup table in D1:E10 with letters A-J in column D and numbers 0 to 9 in column E and the following formula in B11 referencing letters entered in A11 and A12:
=COUNTIFS(A1:A9,1,B1:B9,">="&VLOOKUP(A11,$D$1:$E$10,2,FALSE),B1:B9,"<="&VLOOKUP(A12,$D$1:$E$10,2,FALSE))
works, changing the letters in A11 and A12 gives the correct count according to what they correspond to in the looku in D1:E10.
When you say give third criteria range do you mean:
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
If so then try:
=COUNTIFS(A1:A9;1;B1:B9;AND("<="&9,;">=1"))
ie have two conditional ranges with the second range having both conditions combined with AND()
Maybe what you want(ed) is:
=COUNTIFS(A:A;1;B:B;">=1";B:B;"<=9")
Almost there. I noticed that three criteria ranges and conditions work only if I use "=" sign in a condition. As soon as I use
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
it returns 0. My goal is to eventualy replace the number in a condition with a VLOOKUP command, so the final equation should be smth like
=COUNTIFS(A1:A9;1;B1:B9;"<="&VLOOKUP(...),B1:B9;">=VLOOKUP(...)")
But the "<" and ">" signs mess with this. Still looking for a solution.
This is my entire line, if it offers any further indication. The AND() commands is at the end - and it still results in 0
=COUNTIFS(INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));IF(C6="računska";1;0);INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));AND("<="&VLOOKUP($C$5;$K$203:$N$223;4;FALSE);">="&VLOOKUP($C$5;$K$203:$N$223;3;FALSE)))

Finding matching value in sheet 2 and copy adjacent cells value in sheet 1

I have searched through many similar topics but could find nothing that will do what I need.
I am trying to create a worksheet that will track scores for a darts game.
On Sheet 1 I have two columns that simply tracks each players throws from 501 down to 0
Row 25 is the amount remaining for each player.
In Sheet 2 I have 2 columns. The Column A contains scores that you can check out on, and Column B contains the checkout e.g. (T20, T20, D18). So if the value in row 25 of Sheet 1 matches any of the values in Column A of sheet 2, the I want to display the Value of Column B in the matching row on Sheet 2 Underneath the remaining score on Sheet 1.
Can anyone point me in the right direction?
not sure what you mean exactly, but this formula in row 26 should do the trick:
=index('Sheet 2'!$B:$B;match(A25;'Sheet 2'!$A:$A;0))
if your list separator is comma ,, use that instead of semicolon ;
you might want to use 1 as the third argument of match function, if you want to display the checkout according to the nearest match that is bigger than the number in row 25 and the column A in Sheet 2 is sorted in ascending order (1-9)
or -1 if you want the nearest match that is smaller and column A is sorted in descending order (9-1)
You can use this:
=IFERROR(VLOOKUP(A4, Sheet2!$C$2:$E$65535, 3, FALSE),0)

Resources