2

I keep track of inventory. I need to know the item's age in days. It would be preferable to enter the current age and have it count up from that value. I have this script

function increment() {
    var s = SpreadsheetApp.getActive().getSheetByName('Sheet5').getRange('A1');
    var cur = parseInt(s.getValue());
    s.setValue(cur + 5);
}

My problem is I want to apply this to an entire column, but only want fields in that column currently with a value to increase by 1 each night. If the field is blank today, it needs to be blank tomorrow until a value is manually added.

Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
  • 1
    Had trouble getting the code to post, sorry! – Terry Brown Jul 23 '18 at 00:32
  • To clarify: do you want `0` to increase to `1` (is `0` even a possible value)? Is it literally only that should not be touched? – SamVK Jul 23 '18 at 00:35
  • Not familiar with `SpreadsheetApp` but I'd assume you could just do `if (s !== '') { // code to convert to number and increment }`. – SamVK Jul 23 '18 at 01:13
  • Possible duplicate of [Google Spreadheets Scripts: check if cell is empty](https://stackoverflow.com/questions/41664971/google-spreadheets-scripts-check-if-cell-is-empty) – ricky3350 Jul 23 '18 at 04:45
  • Sam, you are correct. Blank untouched, but any numeric value adds 1 daily. To clarify, it's an inventory sheet and I need to know the age of each item entered. Most items are added on day one, but if I am off a couple days when I return there may be some items I enter that are already two days old or more. The problem I'm having is even blank fields are adding up. – Terry Brown Jul 24 '18 at 03:11
  • Ricky, I was just looking at that and it is close but seems to be the opposite. How do I reverse that? – Terry Brown Jul 24 '18 at 03:14

0 Answers0