Search code examples
google-apps-scriptgoogle-sheetsconcatenationincrement

Increment a concatenate formula with Google Script


I don't find a good solution to automatically increment a concatenate formula starting at row 2 and finishing at row 50.

I already managed to set the concatenate formula in the second row and 10th column with this.

var formula2 = 'CONCATENATE(C1;" - ";D1)'

sheet.getRange(2,10).setFormula(formula2)

How should I do now to increment it automatically from 2 to 50 in the E column ?


Solution

  • How about the following modification?

    From:

    sheet.getRange(2,10).setFormula(formula2)
    

    To:

    sheet.getRange("E2:E50").setFormula(formula2);
    
    • If you want to put CONCATENATE(C2;" - ";D2) to the cell "E2", please modify var formula2 = 'CONCATENATE(C1;" - ";D1)' to var formula2 = 'CONCATENATE(C2;" - ";D2)'.

    Reference: