Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Pulling Apart Cells.

Pulling Apart Cells

by Allen Wyatt
(last updated April 4, 2020)

3

It's probably happened to you before: you get data for your worksheet, and one of the columns includes names. The only problem is the names are all bunched together. For instance, the cell contains "Allen Wyatt," but you would rather have the first name in one column, and the last name in the neighboring column to the right. How do you pull the names apart?

You can easily use the Text to Columns feature in Excel to pull your data apart. Just follow these steps:

  1. Select the range of cells you want to split.
  2. Display the Data tab of the ribbon.
  3. Click the Text to Columns tool, in the Data Tools group. Excel starts the Convert Text to Columns Wizard. (See Figure 1.)
  4. Figure 1. The beginning of the Convert Text to Columns Wizard.

  5. Choose whether the text you have selected is fixed width or delimited. (In the case of a space between first and last name, the text would be delimited.)
  6. Click on Next.
  7. Specify the delimiters you want Excel to recognize. In the case of pulling apart names, you should make sure that you use spaces as delimiters.
  8. Click on Finish.

Excel pulls apart the cells in your selected range, separating all the text at the delimiter you specified. Excel uses however many columns are necessary to hold the data.

If you don't want to spread your data completely across the columns, then you will need to use a macro. For instance, if a cell contains "John Davis, Esq.", then using the Text to Columns feature will result in the data being spread into three columns: the first containing "John", the second containing "Davis," (with the comma), and the third containing "Esq." If you would rather have the data split into two columns ("John" in one and "Davis, Esq." in the other, then the following macro will be helpful:

Sub PullApart()
    Dim Cell As Range
    Dim k As Integer

    For Each Cell In Selection
        k = InStr(Cell, " ")
        If k Then
            Cell.Offset(0, 1) = Mid(Cell, k + 1)
            Cell = Left(Cell, k - 1)
        End If
    Next
End Sub

This macro examines each cell and leaves everything up to the first space in the selected cell and moves everything after the space into the column to the right. The only "gottcha" with this macro is to make sure you have nothing in the column to the right of whatever cells you select when you run it.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9932) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Pulling Apart Cells.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Resizing a Picture

Place a graphic into a worksheet, and it is inevitable that you'll need to change the size of that graphic. Here's the ...

Discover More

Changing Shading when a Column Value Changes

If you have a data table in a worksheet, and you want to shade various rows based on whatever is in the first column, ...

Discover More

Freezing Cell Size when Inserting Pictures

Insert a picture into a table cell, and you may quickly find that the table is no longer the size you expected. Here's ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Easily Adding Blank Rows

Want to add a bunch of blank rows to your data and have those rows interspersed among your existing rows? Here's a quick ...

Discover More

Viewing Formula Results

When editing information in a cell, you may need to know the result of a portion of your formula. The shortcut described ...

Discover More

Disabling Dragging and Dropping

Excel allows you to easily paste information into a worksheet, including through simply dragging and dropping the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 9?

2020-04-06 13:37:15

Karen Mater

To split as shown in the first option (without a macro), you need to have enough blank columns to the left of the column you are splitting, or it will overwrite the content already in that column.


2020-04-05 04:52:57

Peter Atherton

albertan
Create another variable, say k2 to find the next word and change the code to:

Sub PullApart()
Dim Cell As Range
Dim k As Integer, k2 As Integer


For Each Cell In Selection
k = InStr(Cell, " ")
k2 = InStr(k + 1, Cell, " ")
If k Then
Cell.Offset(0, 1) = MID(Cell, k + 1, k2 - k)
Cell.Offset(0, 2) = Right(Cell, Len(Cell) - k2)
Cell = Left(Cell, k - 1)
End If
Next
End Sub


2020-04-04 15:58:22

albertan

Nice technique on VBA. If I want split the 3 word cell into 3 columns, what would be the code in this case? Thank you so much


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.