0

I have a function which should pass a formula to a sheet. The script works well for an ordinary formula but when the formula is query I get an error "missing ; before statement ( line 59...) Here is a snip of the error and code - line 59 ends ...."; enter image description here

Iamblichus
  • 18,540
  • 2
  • 11
  • 27

1 Answers1

0

The problem is caused by the nesting of quotes

The correct way to nest is

  • either to alternate single and double quotes

Sample:

var form1='QUERY(A2:E6,"select avg(A) pivot B", -1)';

  • or to escape the inner quotes with a backslash:

Sample:

var form1="QUERY(A2:E6,\"select avg(A) pivot B\", -1)";

See also here.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • I hope it worked for you. If you found it helpful, please consider accepting it to increase visibility for other users who might encounter the same problem. – ziganotschka Dec 11 '19 at 14:25