+ Reply to Thread
Results 1 to 13 of 13

Remove commas if they are between brackets

  1. #1
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Remove commas if they are between brackets

    Hi there

    Does anyone know a quick formula that allows one to remove all of the commas from a cell if they are between brackets, so (01, 02) becomes (01 02), but text in the same cell that may also include commas are not affected:

    Peanuts, Pizza, Pies (01, 02, 04) = Peanuts, Pizza, Pies (01 02 04)

    Thanks in advance

    Luke

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Remove commas if they are between brackets

    Luke

    Will the (01, 02) or whatever always be at the end of the string?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Re: Remove commas if they are between brackets

    unfortunately not necessarily, the cells have quite a lot of data in them and all are formatted slightly differently

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Remove commas if they are between brackets

    Hi,

    Will there only ever be one such instance to replace in a given string? Or could you have something like, e.g.:

    Peanuts, Pizza (01, 02, 04) Apples, Cherries (03, 04, 09)

    in the same cell, and wish to perform the replacement on both sets of brackets?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Re: Remove commas if they are between brackets

    Hi XOR LX,

    there could be two (or perhaps more) instances like the example you have provides

    All the best

    Luke

  6. #6
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: Remove commas if they are between brackets

    Seems like a job for a macro or custom formula to me.
    Despite the high cost of living, it remains very popular.

    Don't forget to mark threads SOLVED when you get an answer and rep all the geniouses that helped you today!

  7. #7
    Valued Forum Contributor
    Join Date
    10-06-2008
    Location
    Norway
    MS-Off Ver
    2010
    Posts
    365

    Re: Remove commas if they are between brackets

    Hi, with only one set of brackets, maybe (with text in A1):
    =IFERROR(LEFT(A1,SEARCH("(",A1)-1)&SUBSTITUTE(MID(A1,SEARCH("(",A1),SEARCH(")",A1)-SEARCH("(",A1)+1),",","")&MID(A1,SEARCH(")",A1)+1,100),A1)

  8. #8
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Re: Remove commas if they are between brackets

    Thanks for trying to help. I just can't think of how to do this, maybe a macro is needed. The reason that I am trying to do this is because I was to delimit the cell by a comma, but sometimes commas are within brackets, so I just need these to be replaced! Sounds so simple but seems more difficult than I anticipated, I look forward to hearing anyone else's help :-)

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Remove commas if they are between brackets

    Try:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"0,",0),"1,",1),"2,",2),"3,",3),"4,",4),"5,",5),"6,",6),"7,",7),"8,",8),"9,",9)

    Regards

  10. #10
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: Remove commas if they are between brackets

    Here is a custom function if you want to try this...

    Please Login or Register  to view this content.
    edit: To use you can put it into ThisWorkbook in the workbooks VBA explorer or in an addin. Then you can just use it like any other formula in excel.

    XOR's is good if there can only be numbers in brackets and the comma always directly follows the number.
    Last edited by Hawkeye16; 06-24-2014 at 07:47 AM.

  11. #11
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Re: Remove commas if they are between brackets

    thanks so much, seems to work a treat

    Have a great one

  12. #12
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Re: Remove commas if they are between brackets

    great, thanks Hawkeye16, I'll put it into action :-)

  13. #13
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: Remove commas if they are between brackets

    Hi

    I'm glad your problem is solved. This udf would be another option.

    Assuming the opening and closing brackets always come nicely in pairs, like in the examples:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 11-23-2016, 12:22 PM
  2. Macro, to remove commas and remove speach marks
    By 5h1l in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2012, 12:06 PM
  3. [SOLVED] Formula to remove brackets, full stops, commas and spaces
    By MikeNificent in forum Excel General
    Replies: 4
    Last Post: 07-27-2012, 12:45 AM
  4. Remove all data within (brackets)
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2009, 05:39 AM
  5. Remove brackets
    By wei82 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-24-2007, 10:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1