is now part of CreativePro.com!

Use Find/Change to Add Text to Many Table Cells

9

Will asked:

Is it possible to ‘Add/insert’ at the end of a sentence in a table?

The best and quickest way to add text at the beginning or end of many table cells is to:

  1. Select the table cells you want to affect. You can select an entire row or column, or, to select the entire table, just click inside the table with the Type tool and then press Command-Option-A or Ctrl-Alt-A.
  2. Open Edit > Find/Change and switch to the GREP tab (don’t worry, it’s easy!)
  3. Set the Search pop-up menu (the scope) to Selection
  4. Search for ./z and change to $0ABC (where “0” is a zero and “ABC” is whatever text you want to insert at the end of the table cell.
  5. Click Change All

find change grep table cell

That will only place the text (“ABC” in the example) in table cells that are not empty. (I haven’t found a way to place text inside empty cells; if you know of one, type it below in the comments.)

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • Chris says:

    Placing the same text in empty table cells:
    I nearly got it to work with ^$ (caret dollar), from the GREP menu Locations – “Beginning of Para” and “End of Para”.
    It certainly **finds** only empty cells (if the scope of the search is just the table), but I can’t get it to add anything with the Replace text.

  • Vinny 38 says:

    FWIW: Finding ^$ is fine but could catch extra returns. Deactivating the multi-line search can prevent it: (?-m)^$
    My best try to add something in an empty cell is to copy the text to be added (ABC in your example) then replace by ~C (clipboard contents without formatting). However, it comes with two important limitation: “Replace all” does not work. You have to keep hitting the Change/Find button. Second limitation is: for some unknown reason, it does not catch the last cell is empty…

  • Marc Autret says:

    An interesting fact is that the meta-character `\z` (backslash z) actually captures the last insertion point of any cell (or story), but since the content of this insertion point is empty the ‘replace’ feature does not function in the GUI.

    However, at the scripting level those insertion points are all nicely collected and can be augmented this way:


    // Assuming you selected the target cells
    app.findGrepPreferences.findWhat = "\\z";
    var a = app.selection[0].findGrep();
    while( ip=a.pop() ) ip.contents="hello";

    Best,
    Marc

    • Obi-wan Kenobi says:

      Hi Marc,

      My version (a long time ago):

      var myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements(),
      C = myCells.length, c;
      for ( c = 0; c < C; c++) if ( myCells[c].contents == "" ) myCells[c].contents = "–";

      (^/)

  • Marco Nigris says:

    This one worked for me (unfortunately only with “Change/Find” not with “Change All”):

    Search for: \z
    Change to: ABC$0

  • Tobias Wantzen says:

    David, in point 4 you typed »/z« (slash z), which is wrong. Your screenshot is correct and shows »\z« (backslash z). Please correct it above.
    Cheers, Tobias

  • Marion Tussey says:

    We often have to fill empty table cells with an “en dash”. After trying Find/Change unsuccessfully, I found a useful Script, similar to the one already posted. This script places an en dash in each empty cell. Script can be edited to add any desired text, by replacing the en dash in the following line of the code:

    mycells[i].contents = “–”

    SCRIPT:

    try
    {
    var myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
    alert(“myCells:” + myCells.length)

    for(i=0; i<myCells.length; i++)
    {
    if(myCells[i].contents == "")
    {
    myCells[i].contents = "–"
    }
    }
    }
    catch(myError)
    {
    alert("no tables found in the active document")
    }

  • >