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:
Figure 1. The beginning of the Convert Text to Columns Wizard.
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:
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.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Macros often need to select different cells in a worksheet. Here's how you can use macro commands to change which cell is ...
Discover MoreThe macro programming language used in Excel gives you a great many tools that allow you to modify the way that Excel ...
Discover MoreDo you get tired of the dialog box that says "do you want to enable macros" that is displayed when you open a workbook. ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments