Verseau1955 wrote:
Hi Barry,
Your formula works but it seems to contain more elements <like ROW() and COLUMN()> than the examples given in the user guide: =OFFSET(D7,0,0,3,1).
I created my own formula for your table: =IF(ISBLANK(C),"",OFFSET($A$1,1,3)+OFFSET($A$1,2,2)) and it works for the first row but not for the others.
Can you explain what is the purpose of ROW() and COLUMN() in your formula?
I'm trying to create a formula for a chequing account with a column for credit and seperate column for debit.
Hi Verseau,
The guide formula is an example of the OFFSET function alone, written in the simplest form possible.
OFFSET can accept up to five arguments, as noted in the syntax model supplied by the Function Browser:
=OFFSET(base,row-offset,column-offset,
rows,columns)
The last two (in italics ere,light grey as supplied by the Function browser) are optional, and are not needed in this case.
In your first use of OFFSET:
OFFSET($A$1,1,3)
The base cell is A1, the row-offset tells the formula it is to get a value from a cell one row down from A1 (ie. row 2), the column-offset tells the formula to get the value from a cell 3 columns to the right of A1 (ie. column D). The cell at that location is D2, so the function returns the value 1000 from that cell.
The same part of my formula has OFFSET($A$1,ROW()-2,COLUMN()-1,1,1), but the last two arguments are optional and in this case unnecessary, so lets drop them.
OFFSET($A$1,ROW()-2,COLUMN()-1)
ROW() returns a number that is the number of the row containing the formula.
COLUMN() returns a number that is the number of the column containing the formula.
For the formula in D3:
ROW() returns 3, so ROW()-2 returns 1
COLUMN() returns 4, so COLUMN()-1 returns 3
and OFFSET returns the value from the same cell one row below and three columns to the right of A1 as in your example.
The difference comes when you fill either formula down from D3 through the rest of column D, the fixed reference to A1 ($A$1) will remain the same,
as will any function arguments specified as fixed values. That means that when your formula is in D7, OFFSET will still show as OFFSET($A$1,1,3), OFFSET is still looking at the cell one row below and three columns to the right of A1, and again returns the value 1000 from D2.
When the two fixed value arguments (1 and 3) are replaced with the expressions calculating the arguments, the formula still
looks the same, and since this copy of the formula is still in the same column, the value returned by COLUMN() will be the same. But the value returned by ROW() is now 7 instead of 3, and the expression ROW()-2 now returns 5. Substituting the calculated values for the expressions, OFFSET is now using OFFSET($A$1,5,3), and is looking at D6, the cell containing the previous balance.
COLUMN() provides the same adjustment if the formula is filled to the right, or if the formula is used in a different column than D. A column offset from column A of COLUMN()-1 will always return a value from the same column as the cell containing the formula.
=IF(ISBLANK(C),"",OFFSET($A$1,1,3)+OFFSET($A$1,2,2))
=IF(ISBLANK(C),"",OFFSET($A$1,ROW()-2,COLUMN()-1,1,1)+OFFSET($A$1,ROW()-1,COLUMN ()-2,1,1))
Regards,
Barry