web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Office Script / Power ...
Power Automate
Answered

Office Script / Power Automate / large data

(1) ShareShare
ReportReport
Posted on by 152

Hello everyone, I am looking for some advice. This is my current script, it works great, unfortunately now my Excel files is too large and fails when ran through Power Automate, and I am coming up with

Range getCell: The request payload size has exceeded the limit.

How can I take this and adjust it for 30K rows?

 

function main(workbook: ExcelScript.Workbook) {

const currentSheet = workbook.getActiveWorksheet();
const usedRange = currentSheet.getUsedRange();

let values = usedRange.getValues();
let rowCount = usedRange.getRowCount();

for (let i = rowCount - 1; i >= 0; i--) {
if (
values[i][11] == "red" ||
values[i][11] == "blue" ||
values[i][11] == "green") {
usedRange.getCell(i, 1).getEntireRow().delete(ExcelScript.DeleteShiftDirection.up)
}
}}

Categories:
  • Srini007 Profile Picture
    3,490 Super User 2026 Season 1 on at

    Hi @Bill51106 

     

    It's due to the limitation from the OfficeScripts to read the range of excel, Check below link to understand the limits, and also there is a link where it explained how to deal with the larger excel file

     

    https://learn.microsoft.com/en-us/office/dev/scripts/testing/platform-limits

    https://learn.microsoft.com/en-us/office/dev/scripts/resources/samples/write-large-dataset

     

    If you find this reply helpful, please consider giving it a LIKE AND

    If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION

     

    Thanks,

    Srini

  • ARB_wcc Profile Picture
    283 Super User 2024 Season 1 on at

    Just tested the script below with 100k rows, and it's working, but it will take time.

     

    1. Identifies the worksheet to be processed.
    2. Checks the entire used range to see if there's any row that should be deleted.
    3. If none found, it exits promptly.
    4. If rows are found:
    • It repeatedly scans the sheet from bottom to top, deleting rows matching the criteria.
    • This iterative approach avoids indexing issues caused by row deletions.
    • The process stops once a full scan is completed without any deletions.

     

    Script Version 01.gif

     

    function main(workbook: ExcelScript.Workbook) {
     const currentSheet = workbook.getActiveWorksheet();
     const DELETE_COLORS = ["red", "blue", "green"];
     let processedRowCount = 0;
    
     // Check if there's any row to delete at all
     const values = currentSheet.getUsedRange().getValues();
     const hasRowsToDelete = values.some(row => DELETE_COLORS.includes(row[0]));
     if (!hasRowsToDelete) {
     console.log("No rows to delete. Exiting.");
     return;
     }
    
     while (true) {
     const usedRange = currentSheet.getUsedRange();
     const values = usedRange.getValues();
     let deleted = false;
    
     console.log(`Starting a new check. Total Rows: ${values.length}`);
    
     // Start from the last row and move up to avoid index shift problems when deleting rows.
     for (let i = values.length - 1; i >= 0; i--) {
     const value = values[i][0];
    
     processedRowCount++;
     if (processedRowCount % 500 === 0) {
     console.log(`Processed ${processedRowCount} rows so far.`);
     }
    
     if (DELETE_COLORS.includes(value)) {
     console.log(`Deleting row ${i + 1} with value: ${value}`);
     currentSheet.getRangeByIndexes(i, 0, 1, 1).getEntireRow().delete(ExcelScript.DeleteShiftDirection.up);
     deleted = true;
     break; // Exit the loop to refresh the sheet data
     }
     }
    
     if (!deleted) {
     console.log(`Completed. Total rows processed: ${processedRowCount}`);
     break; // If no row is deleted, exit the while loop
     }
     }
    }

     

  • Verified answer
    ARB_wcc Profile Picture
    283 Super User 2024 Season 1 on at

    Actually, never mind about the first script, just try this 2nd version instead because it pulls all the data at once, filters it in memory using JavaScript's optimized functions, and then writes back only the necessary data in one swift operation. This minimizes interactions with Excel, making it ultra-fast even with +200k rows as I just tested.

     

    ezgif.com-optimize (1).gif

     

    function main(workbook: ExcelScript.Workbook) {
     const currentSheet = workbook.getActiveWorksheet();
     const DELETE_COLORS = ["red", "blue", "green"];
    
     // Get all values from the sheet
     const usedRange = currentSheet.getUsedRange();
     const values = usedRange.getValues();
    
     console.log(`Starting with ${values.length} rows.`);
    
     // Filter out the rows with undesired colors
     const newValues = values.filter(row => !DELETE_COLORS.includes(row[0]));
    
     console.log(`Finished filtering. ${newValues.length} rows remaining.`);
    
     // Clear the original range
     usedRange.clear();
    
     // Write the filtered values back to the worksheet starting from the top
     if (newValues.length > 0) {
     currentSheet.getRangeByIndexes(0, 0, newValues.length, newValues[0].length).setValues(newValues);
     }
     console.log(`Process completed.`);
    }

     

  • Bill51106 Profile Picture
    152 on at

    @ARB_wcc Thank you, this works amazingly fast!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 292 Super User 2026 Season 2

#2
Henil Profile Picture

Henil 128

#3
anirudhev Profile Picture

anirudhev 124

Last 30 days Overall leaderboard