I have a formula that is grabbing data from lots of places and putting semicolons between the data. Sometimes, the data comes with semicolons already in place. Sometimes, the data is empty, and I don't want any semicolons.
What I wind up with is a string that sometimes starts with one or more semicolons. When this happens, I want to remove the starting semicolons (I want to start the string at the first non-semicolon character).
Sometimes, the string ends with a semicolon. When this happens, I want to end the string with the last non-semicolon value.
Sometimes, the string will contain multiple semicolons between two substrings (example: Bob;;Dole). When this happens, I want to replace the middle semicolons with a single semicolon.
Much of the spreadsheet is locked, so I would like to do this in a single cell, if possible.
Let's say the current formula is
=FORMULA
I was thinking of something like this to trim the initial and ending semicolons:
=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(FORMULA," ",CHAR(1)),";"," "))," ",";"),CHAR(1)," ")
This takes care of all of the initial and ending semicolons, but not the duplicates in the middle. Is there a simple formula to take care of them?
This gets me close:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(FORMULA," ",CHAR(1)),";"," "))," ",";"),CHAR(1)," "),";;",";")
But, if there are more than 2 consecutive semicolons, like Bob;;;Dole, it only reduces the number of semicolons by 1.
Bookmarks