[Solved] Calc: Auto-increment cell reference

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
belchergb
Posts: 37
Joined: Sun Mar 24, 2013 4:08 am

[Solved] Calc: Auto-increment cell reference

Post by belchergb »

In a macro, I want to fetch the contents of a cell containing a formula with a cell reference and copy it to the next row down. I want the reference to automatically increment to the next row.

For example, in cell B6 there is a formula, "=A6". I want the macro to automatically increment the row reference and store "=A7" in the next row down. Can you point me in the right direction to accomplish that?
Last edited by belchergb on Wed Nov 07, 2018 4:32 pm, edited 1 time in total.
LibreOffice 3.5.7.2 Ubuntu 12.04
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: calc - auto-increment cell reference

Post by RusselB »

I know you asked for this in a macro, but what you're asking for can be easily done without a macro.
Simply enter the initial formula, as you state in your example, then copy the formula in the cell B6 and paste it into the other cell(s) that you want the incremented formula in.
If you don't use absolute cell references, then the row number and column letter will adjust automatically for the pasted formulas.

As to doing this with a macro, I don't have a clue.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
belchergb
Posts: 37
Joined: Sun Mar 24, 2013 4:08 am

Re: calc - auto-increment cell reference

Post by belchergb »

Thanks for that info, RusselB, but I already knew that. For other reasons I specifically want to do it in a macro. It is exactly that "automatic" behavior of calc that I want to do "manually" in a macro. How can I grab a value in a cell, paste it in the next row (things I already know how to do), and have references in it "automatically" incremented as you describe?
LibreOffice 3.5.7.2 Ubuntu 12.04
User avatar
robleyd
Moderator
Posts: 5082
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: calc - auto-increment cell reference

Post by robleyd »

There is a python macro in this topic which you might be able to use as a basis to create your own macro. It may be that the macro will do what you want "out of the box" without modification.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: calc - auto-increment cell reference

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
belchergb
Posts: 37
Joined: Sun Mar 24, 2013 4:08 am

Re: Calc: Auto-increment cell reference

Post by belchergb »

Thank you Villeroy. The copyRange method of sheet is exactly what I need. It takes care of the magical adjustment of cell references in the formula. Thanks for this pointer.
LibreOffice 3.5.7.2 Ubuntu 12.04
Post Reply