Increment your the Active Cell Value +1

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
oguillaume
Posts: 1
Joined: Thu Apr 09, 2009 12:10 pm

Increment your the Active Cell Value +1

Post by oguillaume »

This simple macro will add 1 to the value of the currently selected cell (known as the active cell).
This increment cell value macro is useful when associated with a keyboard shortcut for counting things rapidly.

Simply create a new Macro Sub :
  • In the menus, choose Macros > Organise Macros > OpenOffice Basic,
  • In the dialogue box unfold the following hierarchy "My Macros > Standard > Module 1"
  • Now that Module 1 is selected, click on button Edit
  • Copy and Paste the code below
  • Hit Save (Ctrl-S)
Now all you have to do is Copy/Paste the code below in the editor that opened.

Code: Select all

Sub activecellplus1

ThisComponent.CurrentSelection.value = ThisComponent.CurrentSelection.value +1

End Sub
Now to assign a keyboard shortcut:
  • In Menus, choose Tools > Customize ... ,
  • In Dialog, activate Tab called Keyboard
  • Look for an empty shortcut key in the list and select it
  • Now in the list called "Functions, Categories" scroll at the bottom of the list and look for '+ Open Office Macros'. (Click on the + to unfold) Now continue unfolding '+ User, + Standard, +Module1 '
  • Now in the list called Functions, you should see an entry called 'activecellplus1' . Select it
  • Now click the button called "Modify" and then OK at the bottom

Test it:
  • Choose an empty cell or put a value in a cell (e.g. 5).
  • Select the cell (click on it)
  • Now hit the shortcut you have created and see the value increment by 1
Voila!
OOo 2.3.X on Ubuntu 8.x + BeOS
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Increment your the Active Cell Value +1

Post by Villeroy »

You always work with one cell selected?
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
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Increment your the Active Cell Value +1

Post by Villeroy »

Your macro may destroy calculation models without warning.
A formula like =Count*Price will be modified correctly (increased by one) updating all subsequent formulas, but when I update the preceeding price or count, the calculation cascade turns out to be broken without evidence because your macro has overwritten the formula with it's result +1 without causing errors nor warnings.

This does not happen with the built-in method "paste special" with option "add". That option allows me to add, subtract, multiply or divide any number with all the numbers in a selected range of cells at once. The above formula becomes =(Count*Price)+1 then, so I keep track on what I did.
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
Post Reply