OFFSET function - excel

I have the following formula in a cell:
=IF(Q12,ROUND(SUM(Q12:Q18)/7,2),"")
Now when I drag it down I want it to calculate SUM for Range Q19:Q25 i.e it should be;
=IF(Q19,ROUND(SUM(Q19:Q25)/7,2),"")
I believe OFFSET is the function to add in the formula but I am not sure how to do it.

You are correct, OFFSET will do this job nicely, but in writing your answer, I have had to make a consideration to the fact that I don't know what offset your formula is to the sum range!
This will do the job, and if your formula isnt in row 1, you'll need the change both of the row() - 1 statements to offset the formula back to 0 (i.e. if this formula starts in row 12, change row() - 1 to row() - 12
=IF(OFFSET($Q$12,(ROW()-1)*7,0),ROUND(SUM(OFFSET($Q$12:$Q$18,(ROW()-1)*7,0))/7,2),"")
Having said all of that, you have a conditional (=If(Q12) and a sum pointing to the same place, shouldn't you be checking Q12 for some truth, then summing?
I don't know what your data set is though, so I could be talking rubbish.
Hope this helps!

Taking only the SUM part of your formula and assuming placed in Row1 please try:
=SUM(OFFSET(Q$12,7*(ROW()-1),,7,1))

Related

How to keep formulas working when copy and pasting in Excel?

Is there a way in formulas, other than creating an extra column, to reference the first cell of a table such that I can copy and paste the table and the formulas still work?
=VLOOKUP($A$1, $E$1:$F$12, 2, 0) for B2:B8
Name1 Rate
Sunday 0.1
Monday 0.1
Tuesday 0.1
Wednesday 0.1
Thursday 0.1
Friday 0.1
Saturday 0.1
Sunday 0.1
Name1 is A1.
This should be enough but just in case example is at this link:
https://docs.google.com/spreadsheets/d/19z-LLTj4pcvDCUaoq72qcBicHsT1Gq5Z9i8haPLRIsI/edit?usp=sharing
Not actually sure what does your "formulas still work" mean, but hope it helps. In your example, you use an absolute reference to cells. You can spot it by "$" signs before column name and row number. If you delete those signs - your references will become relative ones. More on the topic can be found HERE.
UPD. So, you need a mix of absolute and relative references. Here is how it could be done. Put this into your B2 cell as a single cell array formula (Ctrl+Shift+Enter). Spread it for the first table - and you are ready to copy it anywhere:
=VLOOKUP(INDIRECT(ADDRESS(MAX((B$1:B1="Rate")*ROW($A$1:A1));COLUMN()-1));$E$1:$F$12;2;0)
It works by searching for the latest row with the "Rate" header. So make sure it is always present. If your header may change - you might be interested in a user-defined formula on VBA.
$A$1:A1 is not important since it's needed only to get numbers for different rows. $E$1:$F$12 is your fixed table.
I don't think this is exactly what you're looking for but piecing together your verbiage to form the question: "Is it possible to reference the first cell of a table?"
Yes!
You can use Index with 1,1 and the Table name. See below example with a sample table called Table1 and the formula to pull the value in the first row and column =INDEX(Table1,1,1). If you wanted the headers, you could modify the formula to read: =INDEX(Table1[#Headers],1,1) which would return "MOND".
Again, probably not what you're looking for, but if anyone does a search, they might find this useful.
Yes you have an option to Copy paste formulas, but the think is that you have to freeze your Formulas properly.
you have Freeze completely $A$1 cell, and copied the same for all which is completely incorrect. You have freeze it as $A1
Corrected Example of your formula : =VLOOKUP($A1, $E$1:$F$12, 2, 0)
The freeze means crating relative cell reference.
Please refer the below link to know about Relative and Absolute Cell Reference completely.
https://www.ablebits.com/office-addins-blog/2015/11/25/relative-absolute-reference-excel/
In end I decided to go with extra column but an example of formula allowing a table to be copied to a different column.
{=INDIRECT(SUBSTITUTE(ADDRESS(1, COLUMN()-1, 4), "1", "")&MIN(IF(OFFSET(L:L, 0, -1)<>"", ROW(OFFSET(L:L, 0, -1)), 9999999)))}
Broken down
SUBSTITUTE(ADDRESS(1, COLUMN()-1, 4) gets column letter string of column one to left, so if we are in column L:L this would return "K". Would need to amend COLUMN()-1 to COLUMN()-2, COLUMN()-3 etc for other columns
OFFSET(L:L, 0, -1) returns K:K.
MIN(IF(OFFSET(L:L, 0, -1)<>"", ROW(OFFSET(L:L, 0, -1)), 9999999))
is equivalent to
MIN(IF(K:K<>"", ROW(K:K), 9999999)) which returns row number of first non-empty cell in column K:K
Formula is array formula
This works provided that:
Table does not share columns with original.
Nothing is above the tables in question.

Incrementing excel formula by two

I have an excel sheet with the following formula:
=('Forecast Workings'!T2+'Forecast Workings'!T3)/1000-4.6
=('Forecast Workings'!T4+'Forecast Workings'!T5)/1000-4.6
=('Forecast Workings'!T6+'Forecast Workings'!T7)/1000-4.6
How can I write this formula so that I can simply drag this down to fill in the rest of the values and that I get the value to increment by 2 each time?
If your initial cell is in first row and you want to multiply you could use:
=(INDIRECT("Forecast Workings!T"&ROW()*2)+INDIRECT("Forecast Workings!T"&ROW()*2+1))/1000-4.6
Subtract value from ROW() if you are not in the first row.
try,
=sum(index('Forecast Workings'!T:T, (row(1:1)-1)*2+2),
index('Forecast Workings'!T:T, (row(1:1)-1)*2+3))/1000-4.6
You will need a helper column, or use indirect and then use a mathematical approach on the formula row() to get the right return. as an example if you start this in row 2 and drag down this will increment by two. (assuming row one are titles)
=INDIRECT("'Forecast Workings'!T" & (ROW()-1)*2)+INDIRECT("'Forecast Workings'!T" & ((ROW()-1)*2)+1)/1000-4.6
I would also advise to check out the code of conduct, you would need to show what you have tried to solve this yourself and what did not work.

How do I Count cells in excel, starting with a cell that has a specified value?

The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10

offset in excel referencing the wrong cell?

I'm trying to use offset to link two sheets in a work book
I am in Sheet2
If I type ='Sheet1'!B6 .... it gives me B6 from Sheet1
If I type +OFFSET('Sheet1'!B6,0,ROW()).... it gives me L6 from Sheet1
Why does it not pick up B6?
If I drag down the second formula it gives me M6,N6,O6,P6 etc, so it's at least consistent.
I've tried everything I can think of to get it to refer to the proper cell but to no avail. It's frustrating as I could have typed the data in by now!
Try
=OFFSET('Sheet1'!B6,0,0)
The "Row()" function is returning a value that is pushing the Offset 11 columns to the right.
Your mistake is you have ROW() in place of column argument ? The 3rd argument in OFFSET is column number and not row number.
Try :
=OFFSET(Sheet1!B6,0,0)
In OFFSET, 0 Row and 0 column means it is the same co-ordinate as the current referenced cell. That is, from Sheet1!B6 increase/decrease 0 rows & 0 columns.
I Have found a solution!!
If I create another column say B in Sheet2 and fill it with 1,2,3,4 etc.I can use the formula like this:-
=OFFSET('Outside funds'!$B$6,0,(B10-1))
It picks up everything correctly.
It may not be the best solution but it works.
Thanks for your help.
To transpose columns to rows, try
=OFFSET('Sheet1'!$B$6,0,ROW()-1)
The second offset parameter is the row offset, the third is the column offset. Make sure to anchor the first parameter otherwise you'll double the offset when you copy down.

Drag down formula and change COLUMN references instead of ROWS

I have this formula in Excel, in row E5:
=SUM(Banco!H$5;Banco!H$6;Banco!H$8;Banco!H$9;Banco!H$10;Banco!H$11)
I need it to change the COLUMN references instead of ROWS when I drag it down (basically behave like I was dragging it across)... For example:
=SUM(Banco!I$5;Banco!I$6;Banco!I$8;Banco!I$9;Banco!I$10;Banco!I$11)
=SUM(Banco!J$5;Banco!J$6;Banco!J$8;Banco!J$9;Banco!J$10;Banco!J$11)
=SUM(Banco!K$5;Banco!K$6;Banco!K$8;Banco!K$9;Banco!K$10;Banco!K$11)
Any clues?
Thanks a lot!
... Use the offset function.
For example - Suppose you had a formula in row 1 and you wanted to reference Banco!H5, you could do something like:
=OFFSET(Banco!$G$5,0,ROW())
Now, as you drag it down, it will offset by the number of rows down you go.
So your new formula would look as follows:
=SUM(OFFSET(Banco!$G$5,0,ROW()),OFFSET(Banco!$G$6,0,ROW()),OFFSET(Banco!$G$8,0,ROW()),OFFSET(Banco!$G$9,0,ROW()),OFFSET(Banco!$G$10,0,ROW()),OFFSET(Banco!$G$11,0,ROW()))
Again, this assumes you are pasting this formula in row 1 (I know it's ugly, but you specified specific cells, so you have to specify each one separately)
Hope this makes sense
Use a combination of the OFFSET and the COUNTA function. The OFFSET function will give the offset of COUNTA columns each time you go down a row. Make the counta function count the number of rows above the row that you're dragging the entire function into (aka each time you drag the function to an extra row, it will add 1)

Resources