Excel multiple rows values addition - excel

i am trying to add the formula that will sum first two rows and excel, put the result in the next column, then move down, take the next two values and put the result below the sum of the previuos one. (it is clear in the picture).
Please any advice would be helpful because my formula is taking the second value and add it on the next one which is not what i need. https://postimg.org/image/st4uie90j/ example

The following formula will work to do what you ask if the columns are adjacent and set the $A$1 to the first cell (top-left of your data set):
=SUM(OFFSET(INDIRECT("R" & (ROW($A$1) +(( ROW()-1)*2)) & "C" & (COLUMN()-1),FALSE),0,0,2,1))

Related

Turning some columns of data into rows, based on the content of specific cells

I have multiple rows of students on a spreadsheet and their grades across the top as column headers. Not all students do every subject I have listed so therefore some columns will be blank. I am trying to use these grades as a range and have the populated cells appear all next to each other at the end of the spreadsheet. I will hen need the subject header to come with the non-blank cells data.
See the screenshot below to understand what data needs to go where:
I found a kind of answer on stack but its totally the wrong way round to how I have to work (see the image below). So, please help me flip this around so names would go down column A and subjects along the first row. (This is in a Google Sheet).
Lee
Here is a mock up of what I am trying to achieve, all data will likely be on one student row, but I have organised like this for the screenshot.
Based on your annotated screenshot, here's how to get from the top table to the bottom table.
Put your Subject 1, etc. headings in manually.
Put ={G13:G16} into G20 to copy your student names.
In H20 use =INDEX(FILTER($H$12:$O$12, $H13:$O13 <> ""), 1, 1) to grab the first heading in $H$12:$O$12 that is over a non-blank cell in $H13:$O13.
In the above formula, FILTER() grabs all the headings over non-blank cells in the range, while INDEX() is used to grab the first result.
Repeat the formula for H21:H23 (letting Sheets update the references that aren't fixed with a $ prefix.)
In I20 use =INDEX(FILTER($H13:$O13, $H13:$O13 <> ""), 1, 1) to grab the first non-blank value in $H13:$O13.
Repeat the formula for I20:I23.
Moving right, just copy the formulas, but update the values for INDEX() but increase the column argument by one. eg. J20 would contain =INDEX(FILTER($H$12:$O$12, $H13:$O13 <> ""), 1, 2) and K20 would contain =INDEX(FILTER($H13:$O13, $H13:$O13 <> ""), 1, 2).
This should get you well on your way.
Happy spreadsheeting!

Excel - Replace offset formula with actual cell reference

I have a table that is pulling thousands of rows of data from a very large sheet. Some of the columns in the table are getting their data from every 5th row on that large sheet. In order to speed up the process of creating the cell references, I used an OFFSET formula to grab a cell from every 5th row:
=OFFSET('Large Sheet'!B$2572,(ROW(1:1)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(2:2)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(3:3)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(4:4)-1)*5,,)
=OFFSET('Large Sheet'!B$2572,(ROW(5:5)-1)*5,,)
etc...
OFFSET can eat up resources during calculation of large tables though, and I'm looking for a way to speed up/simplify my formula. Is there any easy way to convert the OFFSET formula into just a simple cell reference like:
='Large Sheet'!B2572
='Large Sheet'!B2577
='Large Sheet'!B2582
='Large Sheet'!B2587
='Large Sheet'!B2592
etc...
I can't just paste values either. This needs to be an active reference, because the large sheet will change.
Thanks for your help.
And here is one last approach to this that does not use VBA or formulas. It's just a quick and dirty use of AutoFilter and deleting rows.
Main idea
Add a reference to a cell =Sheet1!A1 and copy it down to match as many rows as there are in the main data.
Add another formula in B1 to be =MOD(ROW(), 5)
Filter column B and uncheck the 0s (or any single number)
Delete all the rows that are visible
Delete column B
Voila, formulas for every 5th row
Some reference images, these are all taken on Sheet2.
Formulas with AutoFilter ready.
Filtered and ready to delete
Delete all those rows (select A1, CTRL+SHIFT+DOWN ARROW, SHIFT+SPACE, CTRL+MINUS)
Delete column B to get final result with "pure" formulas every 5th row.
If you want to take a VBA approach to this, you can generate the references very quickly using simple For loops.
Here is some very crude code which can get you started. It uses hard-coded sheet names and variables. I am really just trying to show the i*5 part.
Sub CreateReferences()
For i = 0 To 12
For j = 0 To 5
Sheet2.Range("H1").Offset(i, j).Formula = _
"=Sheet1!" & Sheet1.Range("A5").Offset(i * 5, j).Address
Next
Next
End Sub
It works by building a quick formula using the Address from a reference to a cell on Sheet1. The only key here is have one index count cells in the "summary" rows and multiply by 5 to get the reference to the "master" sheet. I am starting at A5 just to match the results from INDEX.
Results show the formula input for H1 and over. I am comparing to the INDEX results generated above.
Here is one approach using INDEX instead of OFFSET. I am not sure if it is faster, I guess you can check. INDEX is not volatile, so you might get some advantage from that.
Picture of ranges, you can see that Sheet1 has a lot of data and Sheet2 is pulling every 5th row from that sheet. The data in Sheet1 goes from A1:F1000 and just reports the address of the current cell.
Formulas use INDEX and are copied down and across from A1 on Sheet2.
=INDEX(Sheet1!$A$1:$F$1000,ROW()*5,COLUMN())

EXCEL Formulas Sum Everything above specific row

I want to SUM everything above a cell that contains the word "SUMTOTAL". So if I have 50 columns I want it to go to first row that has the text "SUMTOTAL" in it and then Sum everything aboce that word. Is it possible?
Use a MATCH formula to find the row and minus one from it then use an INDIRECT formula to put together a string of the address then plop it into a sum formula like this:
=SUM(INDIRECT("A1:A" & MATCH("SUMTOTAL",B:B,0)-1))
Assumption:
SUMTOTAL is in column B somewhere
The numbers you want to sum are in column A
Your data starts at row 1.
You are summing ONE column. To expand simply change "A1:A" to "A1:X" if you wanted to sum columns A to X
I assume that all your data is located in A1:N20, and SUMTOTAL appears somewhere inside this area (you can easily change the desired data location). The following formula does the summation of all numbers directly above SUMTOTAL, i.e., in the same column.
=SUM(OFFSET($A$1,0,SUMPRODUCT(COLUMN($A$1:$N$20)*($A$1:$N$20="SUMTOTAL"))-1,SUMPRODUCT(ROW($A$1:$N$20)*($A$1:$N$20="SUMTOTAL"))-1))
If you want to sum all numbers above SUMTOTAL, no matter if in the same column or not, use
=SUM(OFFSET($A$1,0,0,SUMPRODUCT(ROW($A$1:$N$20)*($A$1:$N$20="SUMTOTAL"))-1,COLUMNS($A$1:$N$20)))
=SUM(INDIRECT(ADDRESS(1,COLUMN())&":"&ADDRESS(ROW()-1,COLUMN())))

find max of a repeating dynamic range in Excel

This may have a simple solution which I haven't found yet. but here's the situation.
I have a data in Excel sheet:
This is a log file generated from simulations. The simulation is run tens of times (variable) and each run generates one block starting at "-------------------" and ending before the next "-----------------" divider. The number of rows between these dividers is variable but certain things are fixed. the number and order of columns and the first row & cell being the divider, the next row in the same column having date stamp, the next row having column headings. the divider and date stamp are contained in only 1 cell.
What I need to do is mind the MAX of CNT & SIM_TIME for each simulation run. I will then take the average of these. I only need to do this for the "Floor 1" table from the screenshot.
What's the best way to proceed? which functions should I use? (I have Office 2010 if that has new functions not present in 2007)
General approach, by example:
Data sheet: Sheet1
Results on seperate sheet: Sheet2
Number of rows in data: Cell F2
=COUNTA(Sheet1!B:B)
Intermediate result, Row of data set Cell A3
=MATCH(Sheet1!$B$1,OFFSET(Sheet1!$B$1,A2,0,$F$2),0)+A2
Intermediate result, row of next data Cell B3
=IF(IFERROR(N(A4),0)=0,IF(ISNA(A3),"",$F$2),A4)
Max of CNT data set, Cell C3
=IF(B3<>"",MAX(OFFSET(Sheet1!$B$1,$A3+2,0,$B3-$A3-3)),"")
Max of SIM_TIME, Cell D3
=IF(C3<>"",MAX(OFFSET(Sheet1!$B$1,$A3+2,3,$B3-$A3-3)),"")
Date from data set
=IF(D3<>"",OFFSET(Sheet1!$B$1,$A3,),"")
To expand to give results for all available data, copy range C3:E3 down for as many rows as are in data. any extra rows will show N/A in column A and blanks in others
Screen shot of results:
Screen Shot of formulas:
I am not sure i got what you want to do.
Perhaps something like this would work, although it is not automatic. I am making the assumption that the last value of each simulation is the MAX value.
Put the following formula at cell "I4" =if(B5 = "---------" ; B4 ; "")
Pull the cell formula down till the last row of "Floor 1"
Calculate the average =average(I:I). Don't put this type on column I!!!
Notes
use as many "-" as there are at cell B22
you may want to insert a new column between I and J, in order to average SIM_TIME. The procedure is the same. Only the cells change.
You could easily automate this procedure a little bit with macros.

Excel Problems- Calculated value as a cell reference

I'm relatively new to excel programming. I'm working on making a spread sheet that shows exponential decay. I have one column (A1:A1000) of 1000 random numbers between 1 & 10 using the TRUNC(RAND()*10,0) in each cell. The next Column (B1:B1000) has a logic mask =IF(A1=0,1,0) , where if the value in the A cell is 0, then the B cell shows a 1. Next, to find the number of 0's in the A column, I have the next column taking the sum of B1:B1000, which returns the number of 0's that showed up in the first column. I'm sure there's an easier way to do that, but this seems to work fine.
Here's my problem, hopefully it's clear what I'm asking:
Next, I want to take the sum of the logic column (B) from B1:B(1000- the value of the sum from (B1:1000)) in the cell below the cell that calculates sum(B1:B1000). Is there a way to to algebra in a cell formula to reference a cell? More simply, if I want to refer to A3, for example, is there a way to input something like A(2+1) to get A3? Does this make sense?
You can very easily do, in VBA:
ActiveCell.Formula = "=A" & (2+1) & "+15"
In Excel:
=INDIRECT(ADDRESS(2+1, COLUMN(A1)))+15
This will set the formula to "=A3+15". Generally, this is best done with variables, so remember to do that.
In Excel, and as pointed out by Eric, you can write the referance to the cells just like normal strings thanks to INDIRECT() function.
Just make sure that the string passed to INDIRECT() is a valid cell reference.
For example :
=SUM(INDIRECT("B" & 2+7*(H2-1)):INDIRECT("B"&(2+7*H2)-1))
Here, I sum 7 lines for each week (H2). It gives the sum of B2:B8, B9:B15, B16:B22, etc.
Hope my example will help you figure out how to use it in real situation.

Resources