dan
dan

Reputation: 359

Modifying formula to work in appsscripts code

I am looking for some help on modifying an equation so that it works inside appsscript code.

Formula in GoogleSheets: =IF(HOME!T2:T<>"",TRANSPOSE(IMPORTXML(LEFT(HOME!T2:T,FIND("#",SUBSTITUTE(HOME!T2:T,"/","#",4))-1),"//strong[@data-e2e='video-views']")),"")

Line in AppsScript: cell.setFormula("=IF(HOME!T2:T<>'',TRANSPOSE(IMPORTXML(LEFT(HOME!T2:T,FIND("#",SUBSTITUTE(HOME!T2:T,'/','#',4))-1),'//strong[@data-e2e='video-views']')),'')");

Resulting error: error in appsscript

Appreciate any help I can get with this!

Upvotes: 0

Views: 54

Answers (1)

dan
dan

Reputation: 359

Sorry, maybe my brain was just not functioning correctly. I have escaped the quotation marks within the String and hopefully it should work now:

cell.setFormula("=IF(HOME!T2:T<>\"\",TRANSPOSE(IMPORTXML(LEFT(HOME!T2:T,FIND(\"#\",SUBSTITUTE(HOME!T2:T,\"/\",\"#\",4))-1),\"//strong[@data-e2e='video-views']\")),\"\")");

Upvotes: 1

Related Questions