Skip to main content

URGENT: add quotation marks to fields that contain commas


I have an urgent need to find data cells that contain commas and enclose the data with quotation marks

A single table, with identifiable columns where needed.

10 replies

  • Inspiring
  • 3264 replies
  • November 6, 2021

A little dated, but this might help -



kuovonne
Forum|alt.badge.img+17
  • Inspiring
  • 5983 replies
  • November 6, 2021

Would a formula field for each column work?


IF(

    FIND(",", {field name}),

    '"' & {field name} & '"',

    {field name}

)


If some already have quote marks as expected, and some have quote marks that need escaping, you might need something a bit more complicated.


IF(

   AND(

        FIND(",", {field name}),

        OR(

            LEFT({field name}, 1) != '"',

            RIGHT({field name}, 1) != '"'

        )

    ),

    CONCATENATE(

        '"',

        SUBSTITUTE({field name}, '"', '""'),

        '"'

    ),

    {field name}

)




  • Author
  • Known Participant
  • 19 replies
  • November 6, 2021
kuovonne wrote:

Would a formula field for each column work?


IF(

    FIND(",", {field name}),

    '"' & {field name} & '"',

    {field name}

)


If some already have quote marks as expected, and some have quote marks that need escaping, you might need something a bit more complicated.


IF(

   AND(

        FIND(",", {field name}),

        OR(

            LEFT({field name}, 1) != '"',

            RIGHT({field name}, 1) != '"'

        )

    ),

    CONCATENATE(

        '"',

        SUBSTITUTE({field name}, '"', '""'),

        '"'

    ),

    {field name}

)




HOORAY!!! First example should do it. Might I ask how it could be executed for all cells in a column? I only have about 8 columns and could do 'em one at a time.


Many thanks!!!


  • Author
  • Known Participant
  • 19 replies
  • November 6, 2021
kuovonne wrote:

Would a formula field for each column work?


IF(

    FIND(",", {field name}),

    '"' & {field name} & '"',

    {field name}

)


If some already have quote marks as expected, and some have quote marks that need escaping, you might need something a bit more complicated.


IF(

   AND(

        FIND(",", {field name}),

        OR(

            LEFT({field name}, 1) != '"',

            RIGHT({field name}, 1) != '"'

        )

    ),

    CONCATENATE(

        '"',

        SUBSTITUTE({field name}, '"', '""'),

        '"'

    ),

    {field name}

)




I get a circular ref error with

IF( FIND(",", {Favorite Characters}), ‘"’ & {Favorite Characters} & ‘"’, {Favorite Characters} )


here’s the test data in the field Batman, Robin and Starwars


  • Author
  • Known Participant
  • 19 replies
  • November 6, 2021
kuovonne wrote:

Would a formula field for each column work?


IF(

    FIND(",", {field name}),

    '"' & {field name} & '"',

    {field name}

)


If some already have quote marks as expected, and some have quote marks that need escaping, you might need something a bit more complicated.


IF(

   AND(

        FIND(",", {field name}),

        OR(

            LEFT({field name}, 1) != '"',

            RIGHT({field name}, 1) != '"'

        )

    ),

    CONCATENATE(

        '"',

        SUBSTITUTE({field name}, '"', '""'),

        '"'

    ),

    {field name}

)




Oops… same error with this one


IF(

AND(

FIND(",", {Favorite Characters}),

OR(

LEFT({Favorite Characters}, 1) != ‘"’,

RIGHT({Favorite Characters}, 1) != ‘"’

)

),

CONCATENATE(

‘"’,

SUBSTITUTE({Favorite Characters}, ‘"’, ‘""’),

‘"’

),

{Favorite Characters}

)


kuovonne
Forum|alt.badge.img+17
  • Inspiring
  • 5983 replies
  • November 6, 2021

You need to create a new formula field.


  • Author
  • Known Participant
  • 19 replies
  • November 6, 2021
kuovonne wrote:

You need to create a new formula field.


I’ve changed the Favorite Characters from single line text to formula. Do u mean I need another field?


kuovonne
Forum|alt.badge.img+17
  • Inspiring
  • 5983 replies
  • November 6, 2021
Landings_Holida wrote:

I’ve changed the Favorite Characters from single line text to formula. Do u mean I need another field?



Yes. Keep the existing single line text field. Add a new formula field that references the existing field.


  • Author
  • Known Participant
  • 19 replies
  • November 6, 2021
kuovonne wrote:

Yes. Keep the existing single line text field. Add a new formula field that references the existing field.


Hmm… since my current fields layout is critical for export CSV, I suppose I could add another field all the way at the end. But then I’d have to copy the " " text back to Favorite Characters field.


  • Author
  • Known Participant
  • 19 replies
  • November 6, 2021
kuovonne wrote:

Yes. Keep the existing single line text field. Add a new formula field that references the existing field.


most of the Fav Char data is comma free


Reply