Home > Blockchain >  Increment number along with a date on Google Sheets
Increment number along with a date on Google Sheets

Time:07-07

I would like to increment a cell in a column by 1 to 999. The thing is, it contains both a number and a date:

Item 1
001/2022
002/2022
003/2022
...
999/2022

Is there a way to do this? I assume it's possible to "hard code" the date as a string "2022" and increment the value beside it but, would it be possible to maintain the date format? If anyone can provide both answers and how to tackle them in each way, I'd be much obliged. Sorry if there is a reference to something like that, I just can't find it. I'm fairly new to this.

CodePudding user response:

Place this in any cell with at least 998 open cells below it:

=ArrayFormula(TEXT(SEQUENCE(999),"000")&"/2022")

CodePudding user response:

You could split the string by "/", parse & increment the left value and then rejoin the two parts like so:

function testIncrement() {
  console.log(increment("005/2021"));
}

function increment(cellValue) {
  const DIVIDER = "/";
  let [a, b] = cellValue.split(DIVIDER)
  return `${Utilities.formatString("d", parseInt(a)   1)}${DIVIDER}${b}`;
}
  • Related