There is no official way to determine if Microsoft Excel or Google Sheets is running through formulas, however with some versions of Excel =INFO("RELEASE")
will return the version of Excel running, but this doesn't work in Google Sheets.
Thanks to @Slai, =ISERR(-"1pm")
results in TRUE in Excel and FALSE in Google Sheets. Excel doesn't understand how to apply math to a time string value, where Google Sheets does, hence the error.
A simple IF statement using this logic can be =IF(ISERR(-"1pm"),"MS-Excel_formula","G-Sheets_formula")
If the formula you're using returns a number, a more simplified version is =IFERROR(GoogleFormula+"0am", ExcelFormula)
however this won't work for non-numeric returned formulas because it adds 0 to the result which should not change a numeric result. For instance, =IFERROR(1+"0am", 2)
returns 1 in Google Sheets and 2 in Excel.
If Microsoft decides to recognise "1am" or "0am" as numeric time values in future versions of Excel, the above if statements won't work as intended and Excel will attempt to execute the Google Sheets formula.
=ISERR(-"1pm")
results in TRUE in Excel and FALSE in Google Sheets – Slai