Skip to main content
Participating Frequently
Jun 25, 2026 10:52 AM UTC
Answered

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

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?

    Manan JoshiCorrect answer
    Community Expert
    Jun 25, 2026 11:53 AM UTC

    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

    7 replies

    Participating Frequently
    Jun 25, 2026 1:52 PM UTC

    Thank you. It works perfectly now. 

    Translate
    Community Expert
    Jun 25, 2026 3:12 PM UTC

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

    Translate
    -Manan
    Participating Frequently
    Jun 26, 2026 7:45 AM UTC

    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

    Translate
    Participating Frequently
    Jun 25, 2026 11:20 AM UTC

    This is the error I receive

    Translate
    Manan JoshiCommunity ExpertCorrect answer
    Community Expert
    Jun 25, 2026 11:53 AM UTC

    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

    Translate
    -Manan
    Participating Frequently
    Jun 25, 2026 11:19 AM UTC

    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 

    Translate
    Community Expert
    Jun 25, 2026 10:55 AM UTC

    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

    Translate
    -Manan