Not Great at this stuff. I simply recorded me moving cell data up two rows to make room for the new data. It runs great in excel, but when I attached the script in PA, I get the following error.
Power Automate Error
"We were unable to run the script. Please try again.
Runtime error: Line 11: Cannot read properties of undefined (reading 'getRange')
clientRequestId: c3eec077-0165-4842-99c1-23a911ee5121"
Script in Excel
function main(workbook: ExcelScript.Workbook) {
// Refresh all data connections
workbook.refreshAllDataConnections();
let selectedSheet = workbook.getActiveWorksheet();
// Paste to range E1 on selectedSheet from range A1 on selectedSheet
selectedSheet.getRange("E1").copyFrom(selectedSheet.getRange("A1"), ExcelScript.RangeCopyType.all, false, false);
// Paste to range A1 on selectedSheet from range F1 on selectedSheet
selectedSheet.getRange("A1").copyFrom(selectedSheet.getRange("F1"), ExcelScript.RangeCopyType.values, false, false);
let source_Calculations = workbook.getWorksheet("Source Calculations");
// Clear ExcelScript.ClearApplyTo.contents from range B4:E5 on source_Calculations
source_Calculations.getRange("B4:E5").clear(ExcelScript.ClearApplyTo.contents);
// Paste to range B4 on source_Calculations from range B6:E7 on source_Calculations
source_Calculations.getRange("B4").copyFrom(source_Calculations.getRange("B6:E7"), ExcelScript.RangeCopyType.all, false, false);
// Paste to range B6 on source_Calculations from range B8:E11 on source_Calculations
source_Calculations.getRange("B6").copyFrom(source_Calculations.getRange("B8:E11"), ExcelScript.RangeCopyType.all, false, false);
// Paste to range B10 on source_Calculations from range B13:E14 on source_Calculations
source_Calculations.getRange("B10").copyFrom(source_Calculations.getRange("B13:E14"), ExcelScript.RangeCopyType.all, false, false);
}
I don't see any issue with line 11.
// Clear ExcelScript.ClearApplyTo.contents from range B4:E5 on source_Calculations
source_Calculations.getRange("B4:E5").clear(ExcelScript.ClearApplyTo.contents);