Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Pulling Apart Cells.

Pulling Apart Cells

Written by Allen Wyatt (last updated July 23, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


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. Choose Text to Columns from the Data menu. Excel starts the Convert Text to Columns Wizard. (See Figure 1.)
  3. Figure 1. The beginning of the Convert Text to Columns Wizard.

  4. 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.)
  5. Click on Next.
  6. 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.
  7. 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 FirstCol As Integer, FirstRow As Integer
    Dim RowCount As Integer
    Dim ThisRow As Integer
    Dim j As Integer, k As Integer
    Dim MyText As String

    FirstCol = ActiveWindow.RangeSelection.Column
    FirstRow = ActiveWindow.RangeSelection.Row
    RowCount = ActiveWindow.Selection.Rows.Count

    For j = 1 To RowCount
        ThisRow = FirstRow + j - 1
        MyText = Cells(ThisRow, FirstCol).Text
        k = InStr(MyText, " ")
        If k > 0 Then
            Cells(ThisRow, FirstCol + 1).Value = Mid(MyText, k + 1)
            Cells(ThisRow, FirstCol).Value = Left(MyText, k - 1)
        End If
    Next j
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 (2967) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Determining if a Text Selection Exists

Macros are often designed to be run on just a selected portion of a document. It is a good idea to make sure that the ...

Discover More

Spell-Checking Abbreviations

Need to make sure that Word includes abbreviations when you check a document's spelling? Here's how to make sure that ...

Discover More

Automatically Converting to GMT

You know what time it is, right? (Quick; look at your watch!) What if you want to know what time it is in Greenwich, ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (menu)

Determining the RGB Value of a Color

Excel allows you to fill a cell's background with just about any color you want. If you need to determine the RGB value ...

Discover More

Deriving an Absolute Value in a Macro

Need to figure out an absolute value within your macro code? It's easy to do using the Abs function, described in this tip.

Discover More

Replacing Some Formulas with the Formula Results

Macros are often used to process the data stored in a worksheet. Some of these processing needs can be pretty specific to ...

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}] (all 7 characters, in the sequence shown) 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 8 - 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.