Excel -> Need Cell Location reported from MATCH() to yield cell location elsewhere so I can AVG between two cells - excel-2016

Having a tough time explaining what I need. An example at the bottom.
I need to average between two points in a column that is constantly changing depending on the start split between different races. The start point is always at the same cell (LightBeam "S"), cell 502 (including row header) but the end point is always different (athletes go slower or faster).
I used MATCH() to get the endpoint location based on a tag point in another cell (LightBeam "1"), for example, cell 1010 is where the split ends.
How do I go from the cell reporting 1010 to give me the B1010, which is the column where the speed data is?
Because if I can get the cell to report "B502", another cell to report "B1010", I can average them.
If I copy another race and paste it in the end value will change, but I still want it to average the speed within the two markers LightBeam "S" and LightBeam "1" - reporting the AVG Speed correctly each time.
A B C D
Time Speed(kph) LightBeam LBTime(S)
0.00 0.00 S 0.00
0.01 1.00
0.02 2.00
0.03 2.50
0.04 3.40 1 0.04

You can use the Indirect function to get the value of a cell given its address
=INDIRECT("B" & {cell containing 1010})

Related

Add Numbers Until Value Reached

I want to have a threshold value in one cell(A1) and take it as a reference for adding cells.
Suppose I have
A1 - 10
A2 - 4
A3 - 2
A4 - 3
A5 - 4
A6 - 6
I want to add cells based on A1(Threshold).
As A1 is 10, cells from A6:A5 should be added - Result:10
If A1 is 6 then cell A6 should be returned- Result:6
If A1 is 16 then cells from A6:A3 should be added - Result:19
Is this possible without VBA? Can i get count of number of cells in return along with sum?
I've added some progression SUM operation with ROW and OFFSET for the following. Note that I have modified and added to your sample data for more thorough results.
      
The SUM formula in C2 is =SUM(OFFSET($A$2,0,0,MAX(INDEX((SUBTOTAL(9,OFFSET($A$2, 0,0,ROW(1:99),1))<$A$1)*ROW(1:99),,))+1,1)) anf the COUNT is derived in D2 with =MAX(INDEX((SUBTOTAL(9,OFFSET($A$2, 0,0,ROW(1:99),1))<$A$1)*ROW(1:99),,))+1. TBH, I didn't experiment much with zeroes in the data as I was unsure whether you would want to count them in the progression or not.
You can use the INDIRECT() function.
=SUM(INDIRECT("A6:A"&ROUNDDOWN(A1/2,0)))
for the count use
=COUNT(INDIRECT("A6:A"&ROUNDDOWN(A1/2,0)))
It's hard to hit a moving target but for your revised parameters try the following.
=SUM(OFFSET($A$6,0-MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,)),0,MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,))+1,1))
 
=MAX(INDEX((SUBTOTAL(9,OFFSET($A$6,1-ROW(1:5),0,ROW(1:5),1))<$A$1)*ROW(1:5),,))+1
While Excel expects to calculate in a 'down-and-to-the-right' progression, the OFFSET() function will accept parameters to both relocate the starting point and reshape the height and width of the range of cells being summed. Generally, working 'down-and-to-the-right' will allow to leave some breathing room for expansion but you will have to be very careful that you do not attempt to move upwards past row 1 (#REF! error).
OFFSET function
The formula could be simplified if there was any guarantee that nothing of numerical value was ever going to be below A6 but that point has not been addressed so my formulas halt the sum operation at A6.

Formula to work out whether all filled in fields are the same, but ignores those that aren't filled?

I'm trying to work a formula so that a cell reads "Days" if all of the filled in cells in a selection are equal, but ignoring those that equal 0 (or blank, whichever's easier).
I've got a start with all the fields I believe I need (don't have the rep for a screen shot but I'll try and explain)
The sheet is to work out holidays based on hours entered in the "hours" row, with Monday K16, Tuesday L16 etc.
The rows are labelled as follows: hours = manual entry, bank hols = bank holidays between two dates (elsewhere on sheet), hours in bank = total hours that would be worked on bank holidays, is a work day = if(hours="0","0","1").
The cell I want would be somewhere below these, but it wouldn't particularly matter as it will be hidden anyway.
Is there a way to work out whether all the values in the manual input "hours" are equal while ignoring all those in the range if they equal 0 (or are blank).
From this I am wanting to display "Days" if they are the same, else show "hours".
I'm also aware that this may require a bit of VBA which I'm currently looking at, but it'd still be nice to get some feedback on here.
Try this:
=IF(COUNTIF(A1:E1,AVERAGEIFS(A1:E1,A1:E1,">"&0))=COUNTIF(A1:E1,">"&0),COUNTIF(A1:E1,">"&0)&" Days",SUM(A1:E1)&" Hours")
Where the values are in A1:E1
EDIT: edited original formula, please use above corrected formula
Say we want to test A1 thru A13
=IF(SUMPRODUCT((A1:A13<>"")/COUNTIF(A1:A13,A1:A13&""))=1,"Days","Hours")
blanks will be ignored.
Assuming that you are only checking one linear set of data IE:
HRS = 1
Bank Holiday Hrs = 1
Hrs in Bank = 1
then you can try
=IF(MOD(SUM(A2:C2),2),"days","hours")
Where A2:C2 are your rows with the data.
If this requires a unique check of actual hrs then it wont work with any values other than 1 or 0 of course.

How to find the average of the cosecutive specified rows in a column

I want to find the average of every 100 rows consecutively in 2 million rows and save these 2000 values in a new column.
Can any one help me either by a VBA or by a Formula in Excel 2007.
waiting for the reply.
The trick here is to set-it up correctly. With the proper set-up, this is a cinch, really. VBA is just going to make this a wee bit easier, but native formulas can do just as well.
Assume I have values in A1:A1000. A1 has 1, A2 has 2, etc. You get the point. Eventually, A1000 has 1000.
Now, copy the following set-up for the specified cells:
B1: 1
C1: 100
B2: =C1+1
C2: =C1+100
Drag down to B10:C10.
Now, input the following formula to D1:
=AVERAGE(INDIRECT("A"&B1&":A"&C1))
Drag down to D10. Voila. You have the average of each 100-row cluster.
Screenshot:
Let us know if this helps.
A single formula:
=INT((ROW()-2)/100)
in say B2 and copied down (to group in hundreds) and a PivotTable with the ColumnB label as Row Labels and Average of the value label in Σ Values is quite straightforward.
If the banding is required, change the formula for =ROW()-1 and Group in the PT.

Divide rows and then transfer divided values in new worksheet (values: time periods & amounts)

Hope you can help with this:
In worksheet "TOTALS" and Range "M11:N251" there are "from:to" time periods inserted by user ("From" is in "M11:M" and "To" is in "N11:N"). Number of rows (and inserted time periods) may vary. Time periods are quadrimester (4months) but not always 120 days (could be 119, 122 or sth like that - if less than 100 then user must not be allowed to divide). Range "W11:W251" hosts amounts of money. So, for example, "M11:N11" can be 1/1/13-1/5/13 (dd/mm/yy) and W11 just a number (i.e. 98,45).
I want to be able to divide each time period almost by 2 (first part can be 60 days, second part rest of days) and amounts accordingly (depending on the number of days of its divided period) and transfer the divided periods and amounts to a new worksheet (TOTALS2) to -let's say- range "A11:B251" & "G11:G251").
So, in the above example, in "TOTALS2" we'll have 1/1/13-1/3/13 in "A11:B11" and 1/3/13-1/5/13 in "A12:B12", and the divided amounts accordingly to the counted days of "A11:B11" & "A12:B12" in "G11" and "G12".
And so on until there are no more time periods & amounts in TOTALS to divide and transfer to TOTALS2.
How can this be done? Ideas?
Thanks in advance!
If you want to check out the file, then download it:
http://www.sendspace.com/file/5kudcy
Based on the file you give in your link where the values in TOTALS start at row 10 (rather than 11 as stated), the prices are in column S (rather than W as stated) and the values in TOTALS2 are to appear in row 10 onwards (rather than row 11 onwards as stated) the following approach works:
Add 5 columns to worksheet TOTALS. These 5 columns have a header in row 9 and formulae in rows 10, 11, 12, etc. Using columns X, Y, Z and AA the header values in X9:AB9 are
Period, Int.To, Int.From, Proportion1, Proportion2
(where Int. is an abbrevation for intermediate.)
The formulae to use in cells X10 to AB10 are:
X10: =N10-M10+1 Calculates number of days from date M10 to date N10, inclusive.
Y10: =M10+59 Calculates end date of the 60 day period starting on date M10 (i.e calculates last date of first "half period")
Z10: =1+Y10 Calculates day after date in Y10 (start date of second "half period")
AA10: =60/X10 Proportion of whole period that is accounted for by first half-period
AB10: =1-AA10 Proportion of whole period that is accounted for by second half period
The formulae in X10:AB10 can be copied down for as many rows as contain data in worksheet TOTALS, to get something like...
The additional columns in TOTALS now provide the information that you need to split each quadrimester into two "halves". Cols M, N, Y and Z provide the date information and S, AA and AB the values for splitting each quadrimester's costs. To get it to display as desired in TOTALS2 you will also need to add a couple of columns to TOTALS2. I've used columns L and M with the following headers in L9 and M9:
Source, Part
In both L10 and L11 insert the value 1, whilst in M10 and M11 insert the values 1 and 2, respectively. Now add the following formulae to L12 and M12
L12: =1+L10
M12: =M10
Copy the formulae in L12 and M12 down so that columns L and M contain values in at least twice the number of rows (in TOTALS) that you wish to split into first half and second half periods. You should end up with the sequence 1,1,2,2,3,3,4,4 etc in column L and 1,2,1,2,1,2,1,2 etc in M.
The Source column (L) indicates which data row in TOTALS (1=first, 2=second, 3=third, etc) acts as the source of the values to be split in "half" and the Part column (M) indicates which "half" it is (1=first, 2=second).
All that remains is to put it all together using appropriate formulae in columns A, B and G of TOTALS2. The formulae to insert into A10, B10 and M10 are:
A10: =OFFSET(IF(M10=1,TOTALS!M$9,TOTALS!Z$9),L10,0)
B10: =OFFSET(IF(M10=1,TOTALS!Y$9,TOTALS!N$9),L10,0)
G10: =OFFSET(TOTALS!S$9,L10,0)*OFFSET(TOTALS!Z$9,TOTALS2!L10,M10)
Copy these formulae down the rows in TOTALS2 and it should be looking like...
The formulae in col A pick the start dates of the "half" periods using either col M or col Z from the correct Source row in TOTALS, according to whether the Part value is 1 or 2. Similarly, the formulae in col B pick the end dates using cols Y and N of TOTALS. The formulae in G multiply the cost value (col S of TOTALS) by the correct proportion from either col AA or col AB in TOTALS, again according to whether Part is 1 or 2.
I haven't included refinements such as:
preventing periods which are too short (or long) in TOTALS from being split (hint: you can detect this using the Length column in worksheet TOTALS) or
controlling the number of displayed rows in TOTALS2 so that it is exactly twice the number of data rows entered in TOTALS (not too difficult and several ways it can be approached) or
rounding the calculated costs for the two "halves" to 2 decimal places AND making sure that they add back to the original quadrimester cost (it is formatting in the worksheet that is causing only 2 decimals to be displayed and it is not guaranteed that the displayed values will sum precisely to their original source cost - the examples chosen just happen to have this property. Again not too difficult to solve.)
However, the above is a basic solution on which you can build.

In excel, want to only sum certain values(not as easy as SUMIF)?

So I have two columns on named program and one with cost values. The three programs are ABC, A, B, and C. I want to sum the costs of all programs that contain A. All that contain B. And all that contain C. ABC clearly is included in all the sums. The problem is that to get just these programs the spreadsheet has a filter on it which messes sumif up. Can someone help? Here is an example of what I mean:
program cost
A 5.00
B 4.00
ABC 9.00
A 2.00
so I would want in three separate cells "sum with A"=16.00, "sum with B"=13.00, "sum with C"=9.00.
Item | Total
A | 16
B | 13
C | 9
Assuming your above range is in A1:B5, my first formula is the following Array formula:
{=SUM(IF(ISERROR(FIND(B6,$A$1:$A$5)),0,$B$1:$B$5))}
You create an Array formula by entering the formula and holding down the Ctrl+Shift keys while you hit Enter. In my solution, I've created an area where I calculate by totals and have a column (called Item in this case) which indicates the letter I see in the original A column.
If you were trying to enter this using VBA, you would use the FormulaArray property:
Selection.FormulaArray ="SUM(IF(ISERROR(FIND(B6,$A$1:$A$5)),0,$B$1:$B$5))"
Update
Restricting the calculation to only visible cells is a bit more complicated. Suppose we have your original data in cells A1:B5. Let's also suppose our test values start in cell C7 (diagonal to the source data). Our totals formula would look like:
=SUMPRODUCT(SUBTOTAL(3,OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1)), --NOT(ISERROR(FIND(C7,$A$1:$A$5))), $B$1:$B$5)
The following portion returns a range over the cells
OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1)
This portion returns 1 for each visible cell and 0 for invisible cell
SUBTOTAL(3,OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1))
This portion is our criteria. NOT(ISERROR(... will return TRUE or FALSE. The double negative sign -- converts that value into a negative integer and then removes that negation.
--NOT(ISERROR(FIND(C7,$A$1:$A$5)))
Lastly, the SUMPRODUCT function multiplies the matching arrays to each other and executes the sum. The first two arrays return a series of 0's or 1's. If the row is both visible and matches our criteria, then we get 1*1 multipled by the given value in the cell. If the given cell is not visible or does not match the criteria, one of the two return a zero and it zeroes out the entire item.