Require formula

Ron99

Active Member
Joined
Feb 10, 2010
Messages
347
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have data as mentioned below in each row.

,,,,,,,,,,,,,,,,AM,,,,,,,,,,,FE,,,,,,,BA
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,DD,,,,,,
HQ,,,,,,,BB,,,,,,,,,,,,,,,,,,,,,,,DF


The output that I require is as mentioned below.

AM,FE,BA
DD
HQ,BB,DF

Regards,
Vikas
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
is
,,,,,,,,,,,,,,,,AM,,,,,,,,,,,FE,,,,,,,BA
in one cell, or is it a series of cells in one row?

Also what version of Xl are you using?
 
Upvote 0
If it is all in 1 cell then you can perform a triple substitute to remove all additional commas except 1, as such:

E.g. A1 contains ,,,,,,,AM,,,,,,,,FE,,,,,,BA then the following formula will return:

Code:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(44),CHAR(17)&CHAR(18)),CHAR(18)&CHAR(17),""),CHAR(17)&CHAR(18),CHAR(44))

Which gives ,AM,FE,BA

I appreciate this causes a comma at the start however... Using some helper cells I came up with this to clean up the other scenarios (I am sure there are more efficient ways though):

Code:
IF(RIGHT(A1,1)=CHAR(44),SUBSTITUTE(IF(LEFT(A1,1)=CHAR(44),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(44),CHAR(17)&CHAR(18)),CHAR(18)&CHAR(17),""),CHAR(17)&CHAR(18),CHAR(44)),CHAR(44),"",1),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(44),CHAR(17)&CHAR(18)),CHAR(18)&CHAR(17),""),CHAR(17)&CHAR(18),CHAR(44))),CHAR(44),"",(LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(44),CHAR(17)&CHAR(18)),CHAR(18)&CHAR(17),""),CHAR(17)&CHAR(18),CHAR(44)))-LEN(SUBSTITUTE(A1,CHAR(44),""))-1)),IF(LEFT(A1,1)=CHAR(44),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(44),CHAR(17)&CHAR(18)),CHAR(18)&CHAR(17),""),CHAR(17)&CHAR(18),CHAR(44)),CHAR(44),"",1),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(44),CHAR(17)&CHAR(18)),CHAR(18)&CHAR(17),""),CHAR(17)&CHAR(18),CHAR(44))))

EDIT: I suppose you could also do text to columns and join with a TEXTJOIN function, if you have that function that is, depends on the excel version
 
Last edited:
Upvote 0
Wow, this is great! it works exactly the way I was looking for. Thank you for your valuable time.
 
Upvote 0
Another option
=SUBSTITUTE(TRIM(SUBSTITUTE(A2,","," "))," ",",")
 
Upvote 0
Wow I totally overshot this one, those formulas are way better to use than mine! Note to self: Trim is very powerful! Thanks guys

EDIT: Excel Trim is better than SQL Trim!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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
Back
Top