Thanks for coming to InDesignSecrets.com, the world's #1 resource for all things InDesign!

Use Find/Change to Add Text to Many Table Cells

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

David Blatner

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

Latest posts by David Blatner (see all)

  • - November 30, -0001
Tags
Related Articles
Comments

6 Comments on “Use Find/Change to Add Text to Many Table Cells

  1. 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.

  2. 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…

  3. 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

    • 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 = "–";

      (^/)

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

    Search for: \z
    Change to: ABC$0

  5. 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

Leave a Reply

Your email address will not be published. Required fields are marked *