Google-sheets – Change an input value in a cell to another value depending on what the input was

google sheetsgoogle-apps-script

What I would like to do is change a number input in the rating column (G3:G9001) to the corresponding number of stars (from 1-10).

The sheet

However I could not figure out how to do this. As a test I tried to change any input to 'asdasdasd aka test' but the way I tried did not work:

The code

Best Answer

This is more a workaround than a real solution, but add this to the scripteditor and change to sheet name..

function onEdit(e) {
if (e.source.getActiveSheet()
    .getName() !== 'Sheet2' || e.range.columnStart !== 7) return;
e.range.setFormula("=rept(char(9734)," + e.value + ")")
}

Since I do not know how to work with a star symbol (char) in GAS, the script writes a formula to the edited cell (in col G) which replaces the number that is typed in with that number of stars.