简体   繁体   中英

Seperating multiple strings in excel cell

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!

Drop in equations and drag down as needed

B2 = TRIM(LEFT(A2,SEARCH(CHAR(32),TRIM(A2),SEARCH(CHAR(32),TRIM(A2))+1)))
C2 = TRIM(RIGHT(A2,LEN(A2)-SEARCH(CHAR(32),TRIM(A2),SEARCH(CHAR(32),TRIM(A2))+1)))

在此处输入图片说明

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:

  1. Select the cell or column that contains the text you want to split.
  2. Select Data tab, in Data Tools section click on Text to Columns tool.
  3. In the Convert Text to Columns Wizard, select Delimited and then click on Next.
  4. Select the Delimiters for your data. In your case just select Space . You can see a preview of your data in the Data preview window. Click on Next.
  5. Select the Column data format or use what Excel chose for you ( General ). Select the Destination , which is the address of your converted data. In case you want to keep your original data for any reason like comparing you should change the default destination address. I recommend you to change it to the next column address. For example, if your data is on column A and row 1 (address $A$1 ), you should change the destination address to $B$1 . Click on Finished.

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.

方法2:Excel工具和公式

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM