Simplifies the delimiters

kayza

Board Regular
Joined
Apr 29, 2015
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
Hi, all

I try to simplify my data which has an uncertain number of delimiters. sample data as follows
A1 : one-two--three---four----five-----
the results I expect are like this
B1 : one-two-three-four-five

thanks in advance
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
1. Note Mike's suggestion has a typo. It should be
=SUBSTITUTE(TRIM(SUBSTITUTE(A1,"-"," "))," ","-")

2. If your data could actually contain spaces (eg "Green apple-red apple----ripe banana") then this extension of Mike's formula could be used
=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1," ","#"),"-"," "))," ","-"),"#"," ")
 
Upvote 0
2. If your data could actually contain spaces (eg "Green apple-red apple----ripe banana") then this extension of Mike's formula could be used
=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1," ","#"),"-"," "))," ","-"),"#"," ")
@kayza,

If your text could possibly have a # sign in it, then change the red highlighted # signs in Peter's formula to a different symbol that would never appear in your text. Alternately, you could use this variation to Peter's formula that should work with any text that you might normally be expected to have...

=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1," ",CHAR(1)),"-"," "))," ","-"),CHAR(1)," ")
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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