简体   繁体   中英

How do I fix "Missing ; before statement" in a if statement with text

Every time I use text in an if statement it says "Missing ; before statement." My code is

function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Class');
var class = sheet.getRange('Traits!L3').getValue();
  if (class == 'Warlock' ) {
    sheet.getRange('A7:D7')breakApart();
    sheet.getRange('A7:D7')mergeAcross();
  } else {
    if (class == 'Fighter') {
      sheet.getRange('A7:D7')breakApart();
      sheet.getRange('A7:B7')mergeAcross();
    } else {
    }

What it does is break and merge cells based on your class (Warlock and Fighter). Traits!L3 is a data validation that lets you choose a class so if you choose warlock, then it merges 4 cells, if not, (unfinished code). How and why does this show up and is there a way to fix it?

You forgot a . before breakApart() and mergeAcross()

function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Class');
var char_class = sheet.getRange('Traits!L3').getValue();
  if (char_class == 'Warlock' ) {
    sheet.getRange('A7:D7').breakApart();
    sheet.getRange('A7:D7').mergeAcross();
  } else {
    if (char_class == 'Fighter') {
      sheet.getRange('A7:D7').breakApart();
      sheet.getRange('A7:B7').mergeAcross();
    } else {
    }

You should use Data->Named Ranges in google sheets and start naming your cell references then you can call them in code or even formulas by that name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM