Increment
Increment
I am trying to figure out how to increment the contents of a cell. I am going to assign it to a button so I can press one button and have several other cells increment and some decrement. I figured out how to create a macro but I can't find anything on this.
Re: Increment
This macro increases the value of Sheet1.A1 by one with each execution.
Code: Select all
oSheets = ThisComponent.Sheets
oSheet1 = oSheets.getByName("Sheet1")
oCellA1 = oSheet1.getCellrangeByName("A1")
ValueA1 = oCellA1.Value
oCellA1.Value = ValueA1 + 1
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Increment
Thank you! Let me go try it out.
Re: Increment
Concerning the original demand to increment / decrement more than one cells by different amounts in one go:
If you want to apply some incrementing / decrementing of cells by a Sub invoked by a click on an OK-button, you have a basic problem:
A) Either you hard-code the information which cells to treat in what way in the Sub itself OR
B) You find a way to pass that information to a Sub capable to interpret it as needed. This is not specifically supported.
Some viable ways to pass parameters as option B requires you find listed in my recent answer to this question in a different forum:
https://ask.libreoffice.org/en/question ... arameters/ .
All these ways suffer, however, from the need to create/apply a specific syntax for the parameter list, and to analyse it by a Sub.
Using the 'Tag' property 'Additional information' of a form control you can at least write the parameter list in a similar way as it would occur in a function call.
See the attached demonstration.
You need to check the included code to be sure it is safe, and to reload the file then permitting macro execution.
(Of course, you can also move the module to your standard library or create your own version there.)
If you want to apply some incrementing / decrementing of cells by a Sub invoked by a click on an OK-button, you have a basic problem:
A) Either you hard-code the information which cells to treat in what way in the Sub itself OR
B) You find a way to pass that information to a Sub capable to interpret it as needed. This is not specifically supported.
Some viable ways to pass parameters as option B requires you find listed in my recent answer to this question in a different forum:
https://ask.libreoffice.org/en/question ... arameters/ .
All these ways suffer, however, from the need to create/apply a specific syntax for the parameter list, and to analyse it by a Sub.
Using the 'Tag' property 'Additional information' of a form control you can at least write the parameter list in a similar way as it would occur in a function call.
See the attached demonstration.
You need to check the included code to be sure it is safe, and to reload the file then permitting macro execution.
(Of course, you can also move the module to your standard library or create your own version there.)
- Attachments
-
- aoo93394IncDecButton_1.ods
- (11.66 KiB) Downloaded 115 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Increment
download/file.php?id=17567
no macro, no cry
no macro, no cry
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice