Increment A Number In A Cell When Another Cell Is Edited

I use a Google sheet to generate and manage invoices for my clients.

The process is fairly simple.

  • One sheet holds the Name, address and contact details of the client.
  • I enter the clients ID into a box for whom I want to generate the invoice for.
  • This increments a counter which acts as the invoice number.
  • I have another sheet (within the same spreadsheet) that is the invoice template.
  • The invoice number and client details are pulled in from the first sheet. Current date is used for the date.
  • I enter the details related to the job in the invoice.
  • I export the invoice as PDF
  • I save the spreadsheet version with a name (File > Version History > Name Current Version).

Here is the Google Apps Script code that increments the counter.

// Update invoice number when changing the client ID cell B3. 
function onEdit(e) {
  if ( e.range.getA1Notation() == "B3" ) {
    var sCounter = e.source.getRange("B2"); // B2 is the number that is incremented.
    var counter = sCounter.getValue();
    
    counter ++;
    sCounter.setValue(counter);  
  }
}

Add this in Tools > Script Editor of your spreadsheet.

Hello, I am Arun Basil Lal. Thank you for reading!

I am a WordPress product developer and creator of Image Attributes Pro. I am passionate about solving problems and travelling the world.

Divi WordPress Theme - My Review

Divi WordPress Theme
Divi is a WordPress theme that web designers do not want you to know. It comes with a drag-and-drop theme builder. You can build beautiful looking unique websites without touching a line of code. Just choose from one of the many pre-made layouts, or pick elements and arrange them any way you like.

Divi is every WordPress developer's wet dream. Surprise your clients with neat responsive websites and have fun building them.

Divi comes from Elegant Themes. If you enjoy building websites, you *need* an Elegant Themes membership. 87 beautiful themes and 5 plugins for the cost of less than a candy-bar each!


Note: I am an avid user of Divi myself and this is a honest review. I wouldn't recommend something that I do not personally find amazing.

1 Comment.

  1. mukesh says:

    amazing blog. keep writing.

Leave a Reply

Your email address will not be published. Required fields are marked *

*