Improve Microsoft Excel Office Script Performance for Large Ranges
Question details
Improve the speed of an Excel Office Script that processes large worksheets by replacing cell-by-cell operations with a bulk range copy.

- Product
- Microsoft Excel Office Scripts
- Device & OS
- not provided
- Scenario
- The user needs to copy data from columns C through L on Sheet1 to the active worksheet while processing thousands of rows efficiently.
- Observed behavior
- Cell-by-cell reads and writes can make the script slow when the source range contains many rows.
Confirm that Sheet1 exists and that columns C through L contain the data to copy. Decide whether the destination needs values only or whether formulas and formatting must also be retained.
Copy the used range in one Office Script operation
Use this method when copying a large contiguous range. A single range operation reduces the number of workbook calls and is much faster than processing each cell separately.
Office Scripts perform best when data is read, written, or copied in blocks. Get the used portion of the source range once, then copy it to the destination starting cell.
In Excel for the web, open the workbook and select the Automate tab, then select New Script or open the script you want to optimize.
Use getWorksheet("Sheet1").getRange("C:L").getUsedRange() to target only the populated cells in columns C through L.
Add the following bulk copy code: const selectedSheet = workbook.getActiveWorksheet(); const source = workbook.getWorksheet("Sheet1").getRange("C:L").getUsedRange(); selectedSheet.getRange("B1").copyFrom(source);
Select Run in the Automate pane, then check the active worksheet to confirm that the copied range begins at cell B1.

Use WPS Spreadsheets for Efficient Large Excel Workbook Editing
Office Scripts are a Microsoft Excel for the web feature, so WPS Office does not run or troubleshoot those scripts. For everyday work with large Excel files, WPS Spreadsheets is a free, lightweight alternative with a familiar spreadsheet interface, strong format compatibility, and an easy migration path for existing workbooks.

Frequently Asked Questions
Why is my Office Script slow when it processes thousands of Excel rows?
Scripts can slow down when they repeatedly call getCell(), getValue(), or setValue() inside loops. Read, write, or copy a complete Range whenever possible to reduce workbook interactions.
How do I copy columns C through L without including empty rows?
Use workbook.getWorksheet("Sheet1").getRange("C:L").getUsedRange(). This returns the used part of those columns rather than the entire worksheet-column range.
Where does copyFrom place the copied Office Script data?
The destination is determined by the range before copyFrom. For example, selectedSheet.getRange("B1").copyFrom(source) places the source range with its top-left cell at B1 on the active worksheet.
Can Office Scripts copy values without copying formulas?
Yes. Use the bulk copy type for values when available, for example destination.copyFrom(source, ExcelScript.RangeCopyType.values). This transfers displayed values instead of formulas.
Should I use a loop to copy each cell in an Office Script?
Avoid per-cell loops for large transfers. Use copyFrom for a direct range copy, or retrieve values with getValues() and write them once with setValues() when you need to transform the data first.




