IF statement not working

61 views
Skip to first unread message

Corey Bounds

unread,
Jan 8, 2021, 1:30:14 AM1/8/21
to Google Apps Script Community

Hey everyone,
I'm really new to javascript and Google Scripts. I've got the code below. All I'm trying to do is have it look in column K for the set value then if that value exists  copy D2 to D3. also id like it to skip/end/go to the next line if its not met. (just end the macro) but it always seems to copy the formula.
 its just a test for a greater macro I'm trying to figure out.  even when "2" doesn't exists in column K it still runs. if i set it to less than 2 it doesn't run. 
 
any help would be great. Thank you.


var app = SpreadsheetApp;
 var activeSheet = app.getActiveSpreadsheet().getActiveSheet();
 var workingCell = activeSheet.getRange("K:K").getValues();
  
  
 
 
  if (workingCell = 2) {
    activeSheet.getRange('E2').activate();
    activeSheet.getRange('D2').copyTo(activeSheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
   }
   else if(workingCell =! 2);{
      return;
}
}


 

Adam Morris

unread,
Jan 8, 2021, 1:36:23 AM1/8/21
to google-apps-sc...@googlegroups.com
Some issues here, you should use double equal sign == in the if statement. 

Another issue here is that 
getRange().getValues()
Returns a 2D array, so comparing it to 2 won’t work either. 

I’m replying here to point in the right direction. Take some time learning the syntax, working on expanding macros will certainly save a lot of time down the road. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a4c46c94-cb76-4559-b305-74a45b8f465co%40googlegroups.com.
--
Reply all
Reply to author
Forward
0 new messages