Excel Online [Office Script] - How to handle double quotes in Office Script?

kchuphone

New Member
Joined
Jun 6, 2022
Messages
7
Office Version
  1. 2021
Platform
  1. Windows
Hi,
I am trying to use Office Script to update a table with formula but am not sure how to handle double quotes.
For simplicity: here is the formula I want to set all cells in column 12 to: =if(L2="sample","yes","no")

I tried the following but the double quote is not interpreted appropriately . I tried using CHAR(34) but was unsuccessful. Please kindly assist.

function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
selectedSheet.getCell(1, 12).setFormula("=if(L2="sample","yes","no");

}
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
In Access vba I would either use embedded single quotes but I suspect that won't work in Excel formula.
I think the approach is to just double up on the doubles?

"=if(L2=""sample"",""yes"",""no"")
 
Upvote 0
It looks like quotes are treated differently.
I used the script recorder and came up with this.
VBA Code:
  selectedSheet.getRange("F1").setFormulaLocal("=IF(L2=\"sample\",\"yes\",\"no\")");
//your line would be entered as this
selectedSheet.getCell(1, 12).setFormula("=if(L2=\"sample\",\"yes\",\"no\")");
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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
Back
Top