[Solved] Adjust range in formula when inserting column
[Solved] Adjust range in formula when inserting column
Struggling with this one. In the attached E4 totals the numbers in B4, C4 and D4. I would like to insert an extra column after D and call E3 year 4 with E4 having a value of 10. I would like the Total column, which has now moved to column F, specifically cell F4 to show the new total 29. But it doesn't because no matter how many new columns you insert before the Total column the formula remains as =SUM(B4:D4) . Any advice appreciated
- Attachments
-
- addcolumn.ods
- (10.19 KiB) Downloaded 6 times
Last edited by MrProgrammer on Tue Oct 28, 2025 4:18 am, edited 2 times in total.
Reason: Tagged ✓ [Solved]
Reason: Tagged ✓ [Solved]
libreoffice 5.4.1.2 on ubuntu 16.04
Re: Dynamically Change Formula when Adding Additional Column
Hallo
SUM($B4:INDEX(4:4;COLUMN()-1))
Last edited by karolus on Tue Oct 21, 2025 11:13 am, edited 1 time in total.
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (Bookworm) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (Bookworm) (on RaspberryPI5)
Re: Dynamically Change Formula when Adding Additional Column
When I insert a column E, your formula is adjusted automatically.
Make sure the following setting is checked: Tools > Options, LibreOffice Calc > General > Expand references when new columns/new rows are inserted.
I would expect this setting to be stored in the file, but I'm not sure.
Make sure the following setting is checked: Tools > Options, LibreOffice Calc > General > Expand references when new columns/new rows are inserted.
I would expect this setting to be stored in the file, but I'm not sure.
AOO 4.1.15 & LO 25.2.5 on Windows 10
Re: Dynamically change formula when adding additional column
Thank you both very much. Appreciate your time helping me.
libreoffice 5.4.1.2 on ubuntu 16.04
Re: Dynamically Change Formula when Adding Additional Column
There is a configuration parameter called ExpandReference (set to false by default). The appropriate entry may appear in the registrymodifications.xcu file.
⠀
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 25.8
Windows 7,10,11 64-bit
LibreOffice 3.3.0.4 – 25.8
Windows 7,10,11 64-bit
- MrProgrammer
- Moderator
- Posts: 5346
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Dynamically change formula when adding additional column
This is explained in [Tutorial] Formula Adjustments during Copy and Move in the section about inserting cells.
If my option OpenOffice Calc → General → Input settings → Expand references when new columns/rows are inserted is off, when I select column E in your attachment and use Insert → Columns, F4 remains =SUM(B4:D4). However, if the option is on, when I select column E and use Insert → Columns, F4 changes to =SUM(B4:E4). Options are set with OpenOffice → Preferences on a Mac, Tools → Options on other platforms.
Perhaps you want a formula expression which means: the columns of this row from B to the column on the formula's left. Selecting cell E4, I use Insert → Names → Define, Name → Years → Assigned to → $B4:D4 → Add → OK. I typed only one $, as shown. Relative references in a defined name are relative the cell which was active when I used Insert → Names → Define, E4 in this situation. Relative to E4, $B4 means: this row column B. Relative to E4, D4 means: this row one column to the left. In E4, I change the formula from =SUM(B4:D4) to =SUM(Years). Now when I select column E and use Insert → Columns, F4 will still contain =SUM(Years), and it will sum the values in B4:E4, whether the option is on or off, since E4 is the cell to the left of F4. If you don't understand relative references read section 8. Using formulas and cell references in Ten concepts that every Calc user should know.
Read about defined names in Help → Index or in User Guides (PDF) or searching for topics about this in the Calc Forum.
If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
This is in in my registrymodifications.xcu
<item oor:path="/org.openoffice.Office.Calc/Input">
<prop oor:name="ExpandReference" oor:op="fuse">
<value>true</value>
</prop>
</item>
I do not find a corresponding entry in any of the XML files created by performing unzip on an ODS file, so I believe for OpenOffice this is per-user setting and not a per-file setting.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).