is now part of CreativePro.com!

A Script to Apply Cell Styles Based on Content

17

In a recent browse through the InDesign Scripting Forum, I came across another little gem, a script you can use to apply cell styles based on the content within those cells. You can get the script here. You’ll need to open it in a script/text editor and make a couple changes to match your needs, but it’s pretty simple.

I can imagine all kinds of uses for this script. For example, you could apply a different style to cells containing negative numbers, to highlight losses in a financial table, saving you the drudgery (and potential mistakes) of finding and formatting them manually.

20140915-cellstyle5

To tailor the script to your needs, just change the findWhat value inside the quotes in line 3 (the default is Banana), to what you’re looking for. And then change the appliedCellStyle value in line 10 to the name of the cell style you want to apply (the default is Yellow).

20140915-cellstyle6

In this case, I want to find all cells containing a minus sign and apply the cell style Loss, which fills the cell with red and changes the paragraph style applied to the text in the cell.

20140915-cellstyle7

20140915-cellstyle8

The script searches the whole document, so you don’t need to select anything prior to running it.

Before

20140915-cellstyle4

After

20140915-cellstyle5

Note that the script will remove overrides to the cell style.

Also in the scripting forums you can find a script to apply a table style based on content here.

I love how scripts can make InDesign smarter and save you so much time—which could be better spent on building your dream Smoothies-n-Sashimi stand!

Editor in Chief of CreativePro. Instructor at LinkedIn Learning with courses on InDesign, Illustrator, Photoshop, GIMP, Inkscape, and Affinity Publisher.
  • danielfromnz says:

    This is very cool. I’m helping a company with some huge tables and they asked this very thing. Thanks for highlighting it.

  • Who cares about the script, what the heck is that that typeface?

  • Bart Van de Wiele says:

    I have 2 remarks about this:
    – This looks like a great script, thanks for sharing Mike!
    – Everyone knows that smoothies and sashimi are a bad combination

    That is all

  • Mike Rankin says:

    C’mon Bart, you gotta try the salmon smoothie, it’s おいしい

  • Kelly Vaughn says:

    I never would’ve thought I’d ever have a use for that script, but then I got sent an excel spreadsheet with nearly 1000 cells, many of which needed to be particular formatting based on repeated content. That script saved the day! I’m not a scripture, but it was so easy to use. could edit the script, save, and then double click in the scripts panel. Then go back and edit the script again, save, and return to ID to run it again with different modifiers. Thanks so much for sharing!

    • You got caught by auto-correct, Kelly, and your scripter got changed to scripture (in a non-ironic way). It took me a year before I figured out that I could right-click on the “misspelled” word and then choose “Learn” so that stopped happening. :-)

  • Ed says:

    I’m trying to get this script to find a range of numbers in a table selection but can’t quite get it working.

    What would I replace “Banana” with? Indesign doesn’t seem to recognise ()range.

  • Tina says:

    I can’t get it working… I use CS4 (?)

  • Fred Lipari says:

    Great script !
    I use ID CC 2021 and the script shows no problem of compatibility. And I use it every day ^^
    Thanks for sharing it !

    Just for the sake of bringing my experience using it, here are 2 things consider for a possible update of the script:
    – strict content (if the content has some similarities, it doesn’t work nicely For instance, if the celles are “pet” and “small pet”. The word pet is in both cells, but they should be sorted differently)
    – Being able to select a range of paragraph. Right now, if you have other tables in your story, it’s becoming a mess :P

    Anyway, a script is not a magic wand, so thank you very much for it !!

  • Tate Bowers says:

    Does anyone know where this script can be found now. The link isn’t working anymore

  • xavier says:

    Is there a way to target blank cells with no content as well in this script?

    Kind regards !

  • Mauricio Bonifacino says:

    Hi there, regarding the ID Script to Apply Cell Styles Based on Content … awesome resource, how do you do to, in order to select cells that only contain number “1”, it only targets those and avoids cells containg “10”, “11”, “101”, etc.

  • Phil says:

    Hello, how to include the parent pages for the search in this script?

  • >