How to copy formula cell with relative reference in Apache POI - apache-poi

All:
I am pretty new to Apache POI, currently when I try to copy formula cell, it can not automatically change relative cell reference, for example:
cell A1 has formula SUM(A3, B3).
In Excel: if I copy that cell to B2, it can automatically be changed to SUM(B4, C4).
In POI: If I copy that formula, it will just copy that formula, without auto change the reference relatively( the cell B2 is still SUM(A3, B3) )
I wonder if there is a simple way to do the auto change in POI? Thank.

Related

Excel Auto Generates Formula Based on Another Column?

I'm working with an Excel spreadsheet and noticed something interesting.
When there's nothing in cell A1, there's no formula or value in cell B1.
When I enter a value in cell A1, cell B1 generates a formula by itself.
The same thing applies to entire columns A and B.
Does anyone know what function in Excel can make this happen?

Copying Excel Formula and controlling relative reference

In Excel I want to copy a formula down and control the relative cell reference.
For example
In A1 if the formula was =B1 and I copied the A1 formula down to A3 the formula in A3 would be =B3. Is there a way of copying the formula in A1 to A3 and have it equal B2?
That's the default copying behaviour in Excel. Did you try it? In fact, if you want to disable it, you have to write $ in front of the fixed row and/or column denominator, so for example $E$1 would be fixed when copied (useful for things that remain constant).
Edit: I think I can imagine what happens: You probably tried to copy the cell contents from the formula editor field. Copy the cell instead, so just mark the cell in the grid by highlighting it, copy it, highlight your target and paste.
Edit2: And please note that you can just drag the little square at the edge of a highlighted cell to apply that cell's formula to an entire area, using the same relative referencing as with copying.

Cell Formula to link to another cell and use that formula

I'd like to create a sheet that has a master formula. From there, I'd like to have a number of lower cells below use the same cell formula but apply it at it's relative position.
For example, in B1 i would write = a1+1.
In b2, I'd like it to apply the b1 formula, so I'd type in a formula to link to b1, but what I really want is the code in that cell, and to have it be relative, so the output would be a2+1.
In b3, id reference b1 but have it return a3+1.
In b4, id reference b1 but have it return a4+1
In b5, id reference b1 but have it return a5+1
This is a very simplified version of what I need. the benefit of doing this is I can change the formula in B1 and have it cascade to all the cells below it. In reality, I can't just drag down because I'm using a template for financial statements on a per market basis. we have dozens of markets and its a pain in the rear to copy/paste them down each time I want to make a simple formula change.
Thanks for any comments. I'd like to do this without VBA if possible. With VBA it gets easy.
Have you considered Named Formulas? If you use relative references in named formulas, then they will be adjusted if the named formula is used in another cell.
For example: Select cell B2, click Formulas > Name Manager > New, enter a name like B2Formula and let it refer to
=Sheet1!A1+1
No $ signs in the cell reference!!!
Now enter this formula into B2:
=B2Formula
Copy the formula down.
Now you decide you need a different formula in B2. So edit the named formula and change it to
=Sheet1!A1*2
and look at the sheet! You only edited one formula, but all the values in column B have adjusted to that new formula
Named Formulas are VERY powerful, especially when used with relative references. Remember that the references will be relative to the cell that is selected when the named formula is defined. Also, when you need to change a named formula with a relative reference, you need to select the same original cell before editing the named formula.

copy and paste formula with constant cell

I need to make Total_Price calculation of working hours:
Excel sheet looks this way:
Job_name(A1);Time_spend(B1);Total_Price(C1);
And I have hour price in special constant cell - F1.
To get Total_Price I'm using formula =B1*F1. After this I copy cell and paste into all rest cells in C column manually. According this procedure C2 gets formula =B2*F2, but I need =B2*F1.
How to make this procedure more automatic?
Use absolute referencing. Instead of =B1*F1 use:
=B1*$F$1
Adding the $ signs in front of the cell references prevents the reference from changing as you drag the formula.

Copying Cells in Excel

I don't know if stackoverflow is the right place for this question:
I have an Excel table with values in the cells C3, G3, K3 and so on...
Now i want to copy these values in the cells B27, B28, B29 and so on...
Can I manage this in the Excel command line or do I need to write some VBA code?
(I'm using Office 2010)
Put this in cell B27 and copy down as far as you need: =OFFSET(C$3, 0, (ROW()-27) * 4)
I may be misunderstanding the question, but in excel you can simply reference a cell to get it's value, so in C3 enter =B27, and the value from C3 will appear. Repeat for the other cell values you'd like to copy

Resources