Removing a comma inside a parenthesis or parentheses

jeffdolton

Board Regular
Joined
Dec 21, 2020
Messages
69
Office Version
  1. 2010
Platform
  1. Windows
I receive a weekly csv extract from an electronic point of sale system. All purchases made under one transaction are combined in one cell and are separated by a comma. However, a variant of a purchase is shown inside parenthesis. If there is more than one variant then these are separated by a comma within parentheses.

For example 2 x Coffee (Instant, Papercup), Adult Polo Shirt (Large, Navy)

I have a formula to split each purchase type wherever a comma appears but I now need a formula or function to remove a comma wherever it appears inside parentheses. All commas outside parentheses are to remain.

After applying the formula the output should look like this 2 x Coffee (Instant Papercup), Adult Polo Shirt (Large Navy)

Thanks for your help.
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,784
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
Ok thinking out loud as I am not near my pc at the moment I would try the following in stages
assuming your data is in A1
in B1 use SUBSTITUTE(A1,....) to change ), for a ~
in C1 use SUBSTITUTE(B1....) to change , to a space
in D1 use SUBSTITUTE(D1....)to change ~ back to ),

look up the SUBSTITUTE function and replace the ....) above with the correct syntax if I use double quotes on my iPad it produces an error on a pc

doing it in separate columns will allow you to see intermediate results to check allis well at each stage
 

jeffdolton

Board Regular
Joined
Dec 21, 2020
Messages
69
Office Version
  1. 2010
Platform
  1. Windows
Ok thinking out loud as I am not near my pc at the moment I would try the following in stages
assuming your data is in A1
in B1 use SUBSTITUTE(A1,....) to change ), for a ~
in C1 use SUBSTITUTE(B1....) to change , to a space
in D1 use SUBSTITUTE(D1....)to change ~ back to ),

look up the SUBSTITUTE function and replace the ....) above with the correct syntax if I use double quotes on my iPad it produces an error on a pc

doing it in separate columns will allow you to see intermediate results to check allis well at each stage
Many thanks for your quick response. I applied your formula exactly as specified. Unfortunately, the inside brackets were left intact and only one of the outer brackets changed.
 

EXCEL MAX

Active Member
Joined
Nov 11, 2020
Messages
293
Office Version
  1. 2007
Platform
  1. Windows
Try this...
=SUBSTITUTE(SUBSTITUTE(A1;", ";" ");") ";"), ")
 

jeffdolton

Board Regular
Joined
Dec 21, 2020
Messages
69
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

Try this...
=SUBSTITUTE(SUBSTITUTE(A1;", ";" ");") ";"), ")
Thanks, I've tried this and a 'You've entered too few arguments for this function' message is returned.
 

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,784
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows

jeffdolton

Board Regular
Joined
Dec 21, 2020
Messages
69
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

my suggestion works for me

Cell Formulas
RangeFormula
B1B1=SUBSTITUTE(A1,"),","~")
C1C1=SUBSTITUTE(B1,",","")
D1D1=SUBSTITUTE(C1,"~","),")
My apologies, I've copied your three formulae and it works perfectly! Would you do me one last favour and combine the three formulae into one.

Many thanks, Jeff
 

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,784
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
The reason I did in stages was so you can see each stage to check for errors it will be an hour or so before I get back to my pc
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,036
Office Version
  1. 365
Platform
  1. Windows
Could you have something like "2 x Coffee (Instant, Papercup), Adult Shorts, Adult Polo Shirt (Large, Navy)" where the comma after shorts should remain?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,780
Messages
5,598,038
Members
414,205
Latest member
Tushark

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top