Warm tip: This article is reproduced from stackoverflow.com, please click
google-sheets javascript

How to make dynamic consecutive numbers in one column

发布于 2020-03-31 23:01:01

I have a list of bills. I must continuously name them according to my bank accounts.

Normally I would sort my sheet by BANK ACCOUNT and DATE, then tag the NUMBER COLUMN by using the "blue square", and after that, I sort by date again.

I wanna program a script function to iterate through the column NUMBER which defines and read the ACCOUNT column and tag the NUMBER row accordingly. I thought I make a "settings"-column somewhere to define the look of the "auto-formatter":

IF BANK {YY}-BANK-{NUMBER} IF CASH {YY}-CASH-{NUMBER}

In the end, it should look like the example below:

 DATE   NUMBER       ACCOUNT
|------|------------|-------|
 1. Jan  18-CASH-01   CASH
 1. Jan  18-BANK-01   BANK
 2. Jan  18-CASH-02   CASH
 3. Jan  18-CASH-03   CASH
 4. Jan  18-BANK-02   BANK

I made a demo sheet that is free to change or clone. The basic formula is implemented. Only the formula to iterate is missing

https://docs.google.com/spreadsheets/d/1aJRqODUMyJai-aVyTj3_konvc8qpL8idKEHNCs9cxSo/edit?usp=sharing

Has anyone a suggestion or starting point for me? I am not good at google sheets API.

Thank you very much in advance

Questioner
Jan
Viewed
60
JPV 2020-01-31 23:29

Maybe this can be done with a formula? In F1 I entered

={"Format"; ArrayFormula(if(len(D2:D), text(C2:C7, "yy")&"-"& UPPER(D2:D)&"-"&iferror(SORT(ROW(D2:D),SORT(ROW(D2:D),D2:D,1),1)-MATCH(D2:D,SORT(D2:D),0)-ROW()+1),))}

See if that works for you?

EDIT, to match the names of the backaccounts to a range, use vlookup

={"Solution A"; ArrayFormula(if(len(D2:D), text(C2:C7, "yy")&"-"& 
VLOOKUP(D2:D, SETTINGS!A10:C, 2, 0)&"- 
"&iferror(SORT(ROW(D2:D),SORT(ROW(D2:D),D2:D,1),1)- 
MATCH(D2:D,SORT(D2:D),0)-ROW()+1),))}