Not sure if this is the right place to ask (I've been trolling around the web looking for the right place and after a few months decided to just throw my question out there), but here goes:

I've been working with Nested IF Statements and Vlookup in Google Sheets, and I'm looking to do similar things using Google Scripts.

1) There are quite a few, but for the purpose of the question I'm just going to isolate it to one. I have a region of cells, Name (B2), Source (B3), Duration (C1:C2 (Merged Cell)). What I want is an IF statement in Google Scripts that follows the logic of "If C2:C3 = or < 0, clear B2:C3, if not reduce C2:C3 by 1." If there is syntax for the IF statement that allows me to add multiple actions if my conditions are not met, that would also be extremely helpful.

2) Additionally, how can I do a Vlookup in response to a positive or negative response to the above IF statement? As an example, let's say that if C2:C3 > 0, I want some other cell, Resource (E2), to be reduced or increased by an amount— but to get that amount, it has to go to the cell called Source (B3) and Vlookup the Name (B2) on another sheet.

I've attached a link to a simplified and editable version sheet just in case a visual representation would help, but by no means feel obligated to modify it if you don't want to. I just want to know the syntax.



feel free to edit green cells as you fit - everything should get re-calculated (for convenience calculation area is in one sheet ...of course it can be distributed in separate sheets)

demo spreadsheet: https://docs.google.com/spreadsheets/d/


This isn't a complete answer to my own question, but I discovered this much and figured it might be of some help to a passerby and scrub such as myself:

The highlighted portions are what are required for the IF function to work, and the things in-between not highlighted are taken from scripts that I normally triggered individually. This is to say then that almost anything can go inside those brackets.

Bear in mind also that where it says ".getrange(3, 5)", 3 represents a row and 5 represents a column (for some reason this works differently than other parts of the script, as you can see cell ranges labeled as you would except from excel.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.