Forum Discussion
Error when recording a macro (argument is invalid or missing or has an incorrect format)
let selectedSheet = workbook.getActiveWorksheet();
// Set range B3 on selectedSheet
selectedSheet.getRange("B3").setFormulaLocal("=IF(SAPAnalyticsReportÜbersichtKP!A2<>\"\",SAPAnalyticsReportÜbersichtKP!B2)");
}
Line #4: ';' expected.
selectedSheet.getRange("B3").Formula = "=IF(SAPAnalyticsReportÜbersichtKP!A2<>"";SAPAnalyticsReportÜbersichtKP!B2)))"
Can anyone help me with this error!
The error message you are encountering indicates that there is a syntax issue with the formula you're trying to set in cell B3. It seems like you are using JavaScript syntax for string concatenation, but the Excel Script language uses different syntax.
Here is the corrected version of your code:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Set formula in range B3 on selectedSheet
selectedSheet.getRange("B3").setFormulaLocal('=IF(SAPAnalyticsReportÜbersichtKP!A2<>"", SAPAnalyticsReportÜbersichtKP!B2, "")');
}
In Excel Script, you can use double quotes inside the formula string without escaping them. Also, note that the separator for function arguments in Excel formulas is a comma (,), not a semicolon (;). Additionally, I replaced the semicolon (;) in the comparison operator with a comma (,), as it's the correct syntax in Excel formulas. Finally, I added an empty string "" as the third argument in the IF function to specify the value if the condition is false. The text and the steps was created with the help of AI. My knowledge of this topic is limited, but since no one has answered it, I entered your question in various AI. If this not works provide more informations. Welcome to your Excel discussion space!
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and like it!
This will help all forum participants.
- Manju1685Apr 24, 2024Copper ContributorHI,
Thanks for the reply but i stilll have error
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Set range B3 on selectedSheet
selectedSheet.getRange("B3").setFormulaLocal("=IF(SAPAnalyticsReportÜbersichtKP!A2<>\"\",SAPAnalyticsReportÜbersichtKP!B2)");
}
Line 4: Range setFormulaLocal: The argument is invalid or missing or has an incorrect format.
I use ; in my excel for all formulas- NikolinoDEApr 24, 2024Gold Contributor
Adjust the code to use semicolons (;) instead of commas (,) as argument separators in the formula, maybe this is the problem.
function main(workbook: ExcelScript.Workbook) { let selectedSheet = workbook.getActiveWorksheet(); // Set formula in range B3 on selectedSheet selectedSheet.getRange("B3").setFormulaLocal('=IF(SAPAnalyticsReportÜbersichtKP!A2<>""; SAPAnalyticsReportÜbersichtKP!B2; "")'); }
- Manju1685Apr 24, 2024Copper ContributorThanks a lot!