10

Is there an easy way to auto increment integer value in a Google Sheet like Ctrl+A in Vim?

If not, how do I go about creating such a shortcut?

1

2 Answers 2

4

Select the cell above (one less than the required value) and drag down (via the fill handle) with Ctrl depressed.

Works "sideways" as well and up or to the left (normally) decrements by 1.

1
  • You are awesome!
    – Top-Bot
    Mar 18, 2020 at 13:42
1

With the following little piece of code you can increment any number by 1 (or whatever you choose).

Code

function onEdit(e) {
  if(e.value == "_incr") {
    var v = e.range.offset(-1,0).getValue();
    if(typeof v == "number") {
      e.range.setValue(v+1);
    } 
  }
}

Screenshot

enter image description here

Explained

The onEdit trigger is only executed when the input corresponds to the magic word _incr. After that it will check if the value is a number and increment by 1.

Note

This doesn't provide data integrity.

Example

I've created an example file for you: Auto-Increment
Add the code in the scipt editor (Tools > Script editor) and press the save button and you're on the go !!

3
  • hi, thank you for taking the time to respond, im not familiar with google sheets function, would you explain how to trigger the function for certain field?
    – s.amitai
    Apr 8, 2015 at 11:01
  • 1
    If you type in <i>_incr</i>, then for every cell the above number is incremented. You can also create a menu item, so that you don't have to type in anything. Do you want to do that? Apr 8, 2015 at 11:20
  • 2
    i apologize, my description for the problem is uncomplete for who is not familiar with vim, i originally meant for (short) keyboard shortcut to increment in 1 the number assumed to be in the selected field, just like "ctrl+;" set the field to the current date, instead just increment, and again thanks for your time and effort, i dont take that for granted.
    – s.amitai
    Apr 8, 2015 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.