Skip to main content
Participating Frequently
June 25, 2026
Answered

Scripts to Remove Empty Table Cells in Data Merge Fail with Errors

  • June 25, 2026
  • 4 replies
  • 32 views

I am using a data merge for a brochure I am working on. In the brochure there are tables, I would like to remove any cells which are empty by using a script. I have found several online and added them into the script folder (not all at the same time), however I get an error every time. Can anyone help - please?

    Correct answer Manan Joshi

    Looking at the error it seems you have not saved the script properly and it is saved as an Rtf document. Try the following code

    var rowToRemove = [], row;
    var tables = app.documents[0].stories.everyItem().tables;
    for(var i = 0; i < tables.length; i++) {
    for(var j = 0; j < tables[i].rows.length; j++) {
    row = tables[i].rows[j];
    if(row.cells.everyItem().contents.join("") == "")
    rowToRemove.push(row);
    }
    }
    for(var i = 0; i < rowToRemove.length; i++)
    rowToRemove[i].remove();

    Follow https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/ article to properly save the script and execute it. Maybe that is all you need with your current script

    4 replies

    Participating Frequently
    June 25, 2026

    Thank you. It works perfectly now. 

    Community Expert
    June 25, 2026

    So what was it? Was it a problem with the saving of your script or did you need the code that I gave?

    -Manan
    Participating Frequently
    June 26, 2026

    In TextEdit, I formatted as Plain text. Saved it as txt file and then renamed to .jsx and it worked. It was the saving of the script. Thank you for your help

    Participating Frequently
    June 25, 2026

    This is the error I receive

    Manan JoshiCommunity ExpertCorrect answer
    Community Expert
    June 25, 2026

    Looking at the error it seems you have not saved the script properly and it is saved as an Rtf document. Try the following code

    var rowToRemove = [], row;
    var tables = app.documents[0].stories.everyItem().tables;
    for(var i = 0; i < tables.length; i++) {
    for(var j = 0; j < tables[i].rows.length; j++) {
    row = tables[i].rows[j];
    if(row.cells.everyItem().contents.join("") == "")
    rowToRemove.push(row);
    }
    }
    for(var i = 0; i < rowToRemove.length; i++)
    rowToRemove[i].remove();

    Follow https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/ article to properly save the script and execute it. Maybe that is all you need with your current script

    -Manan
    Participating Frequently
    June 25, 2026

    These pages are of the same product but different countries take different versions so the table on the reverse which lists the SKU some have 1 product and some 2. Where there is only 1 product I would like the second row of cells to be removed. Hopefully it will make sense when you see the files? The script is in the InDesign file but also sent a word document with the script 

    Community Expert
    June 25, 2026

    Remove cell would mean what exactly? And share the script and the document and the error only then will we be able to guide you

    -Manan