I'm searching for an excel formula (VBA isn't an option for this scenario) that could split two text strings that appear in a single cell.
Each string can be of any length and contain spaces, but will be seperated by two or more spaces. The first string will almost always be preceeded by multiple spaces, too.
So for example, you may have cells with values like:
north wing second floor
south korea dosan-park
From which I'd want to extract north wing
and second floor
as two seperate cells from the first line and from the second line get south korea
and dosan-park
Any thoughts? Many thanks in advance!
From your examples, I realized that there can be many variations of the data set. To write a formula you should understand the stages and try to make it happen.
Method 1: Formulas
If your data is in cell A1 and we assume that the first part always have two separate strings then the formula is as below for the first part (example: north wing, south korea)
=LEFT(TRIM(A1),FIND(CHAR(1),SUBSTITUTE(TRIM(A1)," ",CHAR(1),2))-1)
and as below for the second part (example: second floor, dosan-park)
=RIGHT(TRIM(A1),LEN(TRIM(A1))-FIND(CHAR(1),SUBSTITUTE(TRIM(A1)," ",CHAR(1),2)))
Method 2: Excel tools and formulas
The other solution I can come up with is using Excel Tools. You can take the text in one or more cells, and split it into multiple cells using the Convert Text to Columns Wizard.
Do as below:
Now you have each string separated in a new cell, you can concatenate them with formulas in a new cell.
After conversion, if you have the words "north", "wing", "second", and "floor" consecutively in cells C1, D1, E1, and F1 then you can use the below formula in cell G1 to concatenate C1 and D1 to make the string "north wing"
=CONCAT(C1," ",D1)
For the second part, I used TRIM because in the case of "dosan-park" the next cell would be empty. This will add extra space at the end of "dosan-park".
=TRIM(CONCAT(E1, " ",F1))
For more clarification look at the screenshot below.
Replacing the formula with value
You can copy (Ctrl + C) the cell with the formula and use paste special (Ctrl + V) then click on the small paste icon that appears near the cell then click on V button .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.