Google Sheets Script =SyntaxError: missing ) after argument list (line 19, file "Reset.gs")

yvettew78

New Member
Joined
Aug 23, 2020
Messages
34
Platform
  1. Windows
  2. Web
Can anyone please help me with the following error.


var cell = sheet.getRange("E44");
cell.setFormula("=IF(AND(E3="Cash",E4="Residential",E5="Single"),VLOOKUP(C10,'RRP Pricing'!A2:G58,2,FALSE),IF(AND(E3="Cash",E4="Residential",E5="three"),VLOOKUP(C10,'RRP Pricing'!A2:G58,2,FALSE),IF(AND(E3="Cash",E4="Residential",E5="three"),VLOOKUP(C10,'RRP Pricing'!A2:G58,3,FALSE),IF(AND(E3="Cash",E4="Commercial",E5="three"),VLOOKUP(C10,'RRP Pricing'!A2:G58,4,FALSE),IF(AND(E3="Finance",E4="Residential",E5="Single"),VLOOKUP(C10,'RRP Pricing'!A2:G58,5,FALSE),IF(AND(E3="Finance",E4="Residential",E5="Three"),VLOOKUP(C10,'RRP Pricing'!A2:G58,6,FALSE),IF(AND(E3="Finance",E4="Commercial",E5="Three"),VLOOKUP(C10,'RRP Pricing'!A2:G58,7,FALSE),0)');

For some reason it comes up with an error when I use it in the script I am creating,
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
You start with a double quote but end with a single quote, try enclosing the entire formula in single quotes.

Also, you need to escape the single quotes around the sheet name.

This code will work but there still appears to be a problem with the formula and I can't quite figure out what.
VBA Code:
  var cell = sheet.getRange("E44");
  cell.setFormula('=IF(AND(E3="Cash",E4="Residential",E5="Single"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,2,FALSE),' +
                  'IF(AND(E3="Cash",E4="Residential",E5="three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,2,FALSE),' +
                  'IF(AND(E3="Cash",E4="Residential",E5="three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,3,FALSE),' +
                  'IF(AND(E3="Cash",E4="Commercial",E5="three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,4,FALSE),' +
                  'IF(AND(E3="Finance",E4="Residential",E5="Single"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,5,FALSE),' + 
                  'IF(AND(E3="Finance",E4="Residential",E5="Three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,6,FALSE),' +
                  'IF(AND(E3="Finance",E4="Commercial",E5="Three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,7,FALSE),0)');
 

yvettew78

New Member
Joined
Aug 23, 2020
Messages
34
Platform
  1. Windows
  2. Web
You start with a double quote but end with a single quote, try enclosing the entire formula in single quotes.

Also, you need to escape the single quotes around the sheet name.

This code will work but there still appears to be a problem with the formula and I can't quite figure out what.
VBA Code:
  var cell = sheet.getRange("E44");
  cell.setFormula('=IF(AND(E3="Cash",E4="Residential",E5="Single"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,2,FALSE),' +
                  'IF(AND(E3="Cash",E4="Residential",E5="three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,2,FALSE),' +
                  'IF(AND(E3="Cash",E4="Residential",E5="three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,3,FALSE),' +
                  'IF(AND(E3="Cash",E4="Commercial",E5="three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,4,FALSE),' +
                  'IF(AND(E3="Finance",E4="Residential",E5="Single"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,5,FALSE),' +
                  'IF(AND(E3="Finance",E4="Residential",E5="Three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,6,FALSE),' +
                  'IF(AND(E3="Finance",E4="Commercial",E5="Three"),VLOOKUP(C10,\'RRP Pricing\'!A2:G58,7,FALSE),0)');
Thank you for your reply.

The code worked but when I run the script Cell E44 comes up with a formulas parse error but if I double click on the cell and press enter, it fixes itself and the error disappears. Any idea why this is happening?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,324
Messages
5,600,956
Members
414,417
Latest member
Nobu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top