Page 1 of 1

Increment your the Active Cell Value +1

Posted: Thu Apr 09, 2009 12:28 pm
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!

Re: Increment your the Active Cell Value +1

Posted: Thu Apr 09, 2009 1:43 pm
by Villeroy
You always work with one cell selected?

Re: Increment your the Active Cell Value +1

Posted: Thu Apr 09, 2009 5:15 pm
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.