Leon Chen
Leon Chen

Reputation: 29

Script works, but only on one spreadsheet

My script works, for the first sheet of my sample spreadsheet. But it does not work for other sheets in my workbook, even though Logger.log(sheet.getName()) successfully fetches the name of the sheet that is currently being edited. It's a pretty simple problem, I just can't figure out why it only works for one of my sheets.

function onEdit (e) {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getActiveSheet()
      Logger.log(sheet.getName())
      if (e.range.getA1Notation() === 'C19' && e.value == 'TRUE') {
        sheet.getRange('K2:K89').setNumberFormat("0.00oz")
      }
        else if (e.range.getA1Notation() === 'C19' && e.value == 'FALSE'){
          sheet.getRange('K2:K89').setNumberFormat("0.00g")
        }

Upvotes: 0

Views: 227

Answers (1)

w2lf
w2lf

Reputation: 50

In 'Loadout Picker' C19 values are TRUE/FALSE

In 'Copy of Loadout Picker 2.0' C19 values are 1/0

In the script in your if loops you have C19 == 'FALSE'/'TRUE'

That's the problem. Just remake a new tickbox at cell C19 in 'Copy of Loadout Picker 2.0' and it will reset the C19 values to TRUE/FALSE from 1/0. (Don't forget to rejoin the spreadsheet or just switch between the sheets so the code starts to work.)

That's also why onEdit() worked for the first sheet and not second.

Upvotes: 2

Related Questions