In Excel, I have the following formula:
=SUBTOTAL(9;INDIRECT("D$"&$B$2&":D$"&$B$3))
It counts the values of a range, which size is defined in other fixed table cells.
B2 = starting point = 9
B3 = end point = 17
So in short:
=SUBTOTAL(9;D9:D17)
I now want to copy that formula to other cols in the same row, I want to pull it to the right (I don't know how that feature is called in Excel). How can I achieve, that only D changes to E and then to F and so on, by the base of my formula? The size of the range should remain the same and has to be linked to table cells B2 and B3.
It's normally better to use INDEX rather than INDIRECT in these type of formulas. One advantage is that the formula can be dragged across....try this version
=SUBTOTAL(9;INDEX(D:D;$B$2):INDEX(D:D;$B$3))
Related
I need to make a sum of 12 rows every 3 rows in excel. That is, I need to sum first from C4 to C15, then from C7 to C18, and so on.
You can use OFFSET function for this, also volatile, but shorter!
Assuming first formula in E2 copied down
=SUM(OFFSET(C$4,(ROWS(E$2:E2)-1)*3,0,12))
I prefer this because it explicitly contains all the required information
C4 = first cell to sum,
E2 = first cell with formula,
3 = row increment,
12 = number of cells to sum
The above gives you the sums on successive rows from E2 (or any other chosen cell) down. If you actually want the sum to be shown every 3 cells e.g. on the first row for each sum then that's simpler - try this formula in D4 copied down
=IF(MOD(ROWS(E$2:E2),3)=1,SUM(C4:C15),"")
.......or even easier.....just put this formula in D4
=SUM(C4:C15)
....leave D5 and D6 blank, then select the range D4:D6 and drag down
You can also use the non-volatile INDEX function
=SUM(INDEX(C:C,ROWS($1:1)*3+1):INDEX(C:C,ROWS($1:1)*3+12))
This works because INDEX returns a reference so you can use the normal Ref1:Ref2 notation for a range.
=SUM(INDIRECT("C"&ROW(1:1)*3+1&":C"&ROW(1:1)*3+12))
Be warned that INDIRECT() is a volatile formula... This means that any change made anywhere in the workbook this formula will recalculate and can cause performance issues.
I'm trying to create a spreadsheet in excel which creates a sequential number in a column (B) depending on the contents of another column. Currently, there are two possibilities of what could be in Column A ("BI" or "GF"). So I want the data to look like this
COL A COLB
BI 1
BI 2
GF 1
BI 3
GF 2
GF 3
BI 4
BI 5
I've tried several attempts to do this but can't seem to find a solution. Any help would be greatly appreciated.
In B2, try this formula:
=CountIf(A$2:A2,A2)
Try to use the offset equation.
The first cell in COL B will look similar to this:
=COUNTIFS(OFFSET(A$1$1:A1,0,0),A1)
The second should look like this:
=COUNTIFS(OFFSET(A$1$1:A2,0,0),A2)
Drag this down in Col B as far as desired. If you are using a table this should autofill.
Explanation:
Essentially you are using the OFFSET formula to create a dynamic range.
The A$1$ serves as the start of your range by making this an absolute reference and the A1 will serve as the end of your range.
By making the ending cell a relative reference, the array the COUNTIFS function search will never go beyond the row the of the cell the formula is relative of.
In your example, the formula in the first row in Col B would result in 1. The reason is the OFFSET returns the array of A$1$:A1 and the COUNTIFS searches through that array and returns a count of all cells equal to A1 which is "BI".
The second row retains the original starting cell for the array of A$1$ however the end of the array is A2. So the COUNTIFS function sees the new array to search through to be A$1$:A2. The COUNTIFS then searchs through each cell equal to A2 which like A1 is "BI". There are two cells equal to "BI" in the new array and thus the reult is 2.
How this works like you want is displayed in the third row of Col B.
The OFFSET functions simply expands the array size to A$1$:A3. The COUNTIFS will work as it normally does, it takes the array, called the criteriarange in Excel, and performs a count for all items that equal A3. A3 in this case is equal to "GF" and in the array A$1$:A3 there are two cells equal to "BF" and one equal to "GF".
Hope this helps!
A list of names (Sheet "Name") which need to put on the following sheet in 5 (preferably variable number) row gaps.
A3 = Name!A1
A9 = Name!A2
A15 = Name!A3
A21 = Name!A4
I've tried using the ROW() in conjunction with IF/THEN/ELSE condition loop,checking for blank row, which fell short. More googling has lead me to the the offset() operand but that's accessing cells rather than writing in them.
I'm quite happy to use VBA active cell but the VB editor doesn't work properly on this machine so for the time being i'm trying to solve this task using EXCEL.
Ooption A:
Put this formula into A3,
=INDEX(Name!A:A, INT(ROW()/6)+1)
Copy to A9, A15 and A21.
Option B:
Put this formula into A3,
=IF(NOT(MOD(ROW()-3, 6)), INDEX(Name!A:A, INT(ROW()/6)+1), "")
Fill down to A21.
Alternatively, you can offset based on the number of rows you've already filled.
=OFFSET(Name!$A$1,counta(A$1:A2),0)
This will work as long as there is no content within other rows between A3,A9,A15,A21.
A little more dynamic would be to add a reference row in the Name tab that would allow you to do a VLOOKUP/MATCH/etc within the new tab. That is very handy when you want to make a variable number of rows in the new tab for each row in the other tab (for example, table 1 lists a quantity and you need a row for each quantity in the next tab--the lookup reference would be a cumulative sum of all of the quantities and you could lookup to that reference).
I am trying to display the total sum of all the numbers for a particular column. I want the sum to be displayed above the column as follows:
21 30
A B
6 5
6 10
6 10
3 5
I know I can sum the values and display it at the bottom of the column using =SUM(A3:INDIRECT("D"&ROW()-2)), however I am not getting a way to display it at the top of the column.
Please guide.
Based on the comments and the previous answers I suggest following formula, entered in cell A1:
=SUM(OFFSET(A$2,0,0,ROWS(b:b)-1))
You can then copy/paste to the right till second last column.
You could also modify your formula in A1 like this to achieve the same:
=SUM(INDIRECT("A2:A"&ROWS(A:A)-2))
But then you cannot copy/paste to the right...
A more general approach with your idea would be:
=SUM(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROWS(A:A),COLUMN())))
You can then copy/paste to the right till last column.
Some explanations:
Both formula sums up every value in the range from A2 till the bottom of column A (i.e. for Excel 2010 this would be A2:A1048576)
It doesn't matter if there are blanks or cells without value; the formula sums up only the numbers
I put A$2 and B:B in the OFFSET formula to avoid circular references, since I'm writing in cell A1 and I cannot write A$1 nor A:A
With the INDIRECT formula you don't have to worry about circular references
Further commenting (sorry, I don't have the credits to comment at the right place under the question):
Phylogenesis formula =SUM(A3:A65535) could also do the work, isn't it?
Didn't understand your question at first, because you talk of "sum of all the numbers for a particular row" but then you sum columns, isn't it?
When I'm doing something like this, I prefer to not include any empty cells beneath the range I'm summing, because I've had errors in the past as the result of including them (usually because there's a cell way down in the column somewhere that I'm not expecting to have a value). I'm assuming that A & B are your column headers. Assuming that, here is how I would do it. This is your formula for cell A1:
=SUM(OFFSET(A$1,2,0,COUNTA(A$3:A$65535)))
Explanation
I'm updating this with a brief explanation, per the OP's request.
According to ExcelFunctions.net:
The Excel Offset function returns range of cells that is a specified number of rows and columns from an initial supplied range.
The function reference for OFFSET is:
=OFFSET(reference, rows, cols, [height], [width])
What this formula does is create a dynamic range based on the number of cells in the selection, relative to cell A$1. This is an offset of two rows and no columns, which starts the range at A$3. The height of the range is the total number of filled cells in the range A$3:A$65535. The assumption here is that there are no blank cells in the range, which there were not in the sample data.
I have a range B3:Bn with dates and a range C2:Y2 with another dates range. I am trying to find a date from a range B3:Bn in a range C2:Y2 and then starting from this cell to sum values. To do this i use:
=SUM(OFFSET(C3;0;MATCH(B3;$C$2:$Y$2;0)):Y3)
But instead of Y3 I would like to say: Sum values just starting from offset cell value till + 7 other columns.
Maybe someone can help with it?
Thanks!
In the table of the figure, cell B6 contains
=SUM(INDEX(A2:P2,1,B4):INDEX(A2:P2,1,B4+B5-1))
You may use an adapted formula to carry out your task.
It indirectly sets (with INDEX) the initial and final cells for carrying out the sum. I defined it as a starting cell (column 3 of range A2:P2) and a number of cells (4).
Points to consider:
You may need to use absolute referencing for some column/row references.
You may define your range to sum in slightly different ways.
You can use the INDIRECT function. It allows you dynamically create a cell range in a formula. So you could have one cell with a forumla that create your cell range as text e.g.
=B1&":"&B2 // in Cell C1, assuming B1 is "A1" and B2 is "A2" this would result in "A1:A2"
And then you can dynamically create a cell range from that using Indirect which you can then use function SUM on.
=SUM(INDIRECT(C1)) // would result the SUM(A1:A2) in our example