I am trying to use AppleScript to set the formula of a cell in Microsoft Excel. I am running into an error but I don't have enough AppleScript knowledge to understand or fix the error and need some help. It seems to be treating part of the formula as a variable. It stops at the word History, colored in green and mentions the variable can't be made into real type in the error. I want the entire string to be treated as text it inserts into the cell. I realized I needed to escape the quotes but it is still not working. I think there is a problem with the commas and the quotes too. Any help would be appreciated!
Tell application "Microsoft Excel"
tell active sheet
set formula of range "E2" of active sheet to "=IF(J2=/" & History /" & , /" & level2 / ",IF(ISNUMBER(SEARCH(/" & ICU / “,level2)),/“ & ICU / ", /" & level3 / "))"
end tell
end tell