How to Convert Text to Columns in Excel with Multiple Spaces

The sample dataset is given below where the column named Name City Designation has mixed information using multiple spaces. We want to separate the values.

Dataset for Converting Text to Columns in Excel with Multiple Spaces


Method 1 – Use the Text to Columns Feature

Steps:

  • Select cells C4:C15.
  • From the Data tab, go to the Data Tools option.
  • Choose the Text to Columns feature.

Use of Text to Columns Feature in Excel

You will see a new dialog box named Convert Text to Columns Wizard – Step 1 of 3.

  • Mark Delimited – Characters such as commas or tabs separate each field.
  • Press Next.

You will see another dialog box named Convert Text to Columns Wizard – Step 2 of 3.

  • Mark Space under Delimiters. You will immediately see the modified data in the Data preview box.
  • Press Next.

You will see a dialog box named Convert Text to Columns Wizard – Step 3 of 3.

  • Mark Text under the Column data format. You should mark the Column data format based on your data type.
  • Keep the Destination as-is.
  • Press Finish.

You will see the warning from Microsoft Excel.

  • Press OK on it.

You will see the separated columns.

Converted Text with Multiple Spaces to Columns in Excel

Read More: How to Convert Column to Text with Delimiter in Excel


Method 2- Applying Keyboard Shortcuts in Excel

Steps:

  • Select the dataset.
  • Press Alt + A + E.

Using Keyboard shortcuts to convert text to columns in Excel with multiple spaces

You will see the dialog box named Convert Text to Columns Wizard – Step 1 of 3.

  • Follow the rest of Method 1 to go through the Text to Columns Wizard.

You will get the separated columns.

Converted Columns from Text with Multiple Spaces in Excel


Method – Using Flash Fill to Convert Text to Columns

Steps:

  • Create three additional columns to store the results.
  • Write the target results manually, row-by-row, until you start getting Excel’s suggestions. We needed to write up to 3 rows to get the suggestion.

Employing Flash Fill Feature to Convert Text to Columns

  • Once you see a preview of the result values in cells down the column, press Enter.

  • Repeat for the other cells.

If you are using an older version of Excel instead of 365:

  • Write the target results for the first three rows (including the headers).

  • Select cells D4:D6, go to the bottom-right corner of the D6 cell, then drag the Fill Handle icon down.

Using Fill Handle icon to Convert Text to Columns in Excel

  • Click on Auto Fill Options and select Flash Fill.

You will see the following output.

  • Repeat for the other columns.

Converted Text to Columns with Multiple Spaces using Flash Fill


Method 4 – Using VBA to Separate Text into Columns with Multiple Spaces

Steps:

  • Save the Excel file as an Excel Macro-Enabled Workbook (*xlsm).
  • Go to the Developer tab and select Visual Basic.

Using VBA to Separate Text into Columns with Multiple Spaces

  • From the Insert tab, select Module.

  • Insert the code given below in Module1.
Option Explicit
Public Sub Converting_Text_to_Columns()
Dim my_cell As Range
Dim my_first_row As Integer
Dim my_last_row As Integer
Dim split_data() As String
Dim i_L As Long, j_L As Long
my_last_row = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For my_first_row = 4 To my_last_row
Set my_cell = Cells(my_first_row, 3)
split_data = Split(Expression:=my_cell.Value, Delimiter:=" ")
For i_L = LBound(split_data) To UBound(split_data)
If Trim$(split_data(i_L)) <> vbNullString Then
my_cell.Offset(ColumnOffset:=j_L).Value = Trim$(split_data(i_L))
j_L = j_L + 1
End If
Next i_L
j_L = 0
Next my_first_row
End Sub

VBA Code to Convert Text to Columns with Multiple Spaces

Code Breakdown

  • We have created a Sub Procedure named Converting_Text_to_Columns.
  • We declared some variables my_first_row and my_last_row as Integer, my_cell as Range, split_data as String, and i_L and j_L as Long.
  • We used VBA Split functions to split the text into columns based on space delimiters.
  • We used a For Loop within the IF Statement along with the VBA Trim function to trim spaces from multiple texts.
  • We want to convert multiple rows of values with the outer For Loop.

  • Save the code and go back to Excel File.
  • Select the cells containing text and, from the Developer tab, select Macros.

  • Select the created Macro (Converting_Text_to_Columns) and click on Run.

You will see the separated columns.

Read More: How to Split Text to Columns Automatically with Formula in Excel


How to Convert Text to Columns with Multiple Delimiters in Excel

See the following dataset where the column named Name City Designation has mixed information using not spaces and commas.

How to Convert Text to Columns with Multiple Delimiters in Excel

  • Follow the steps of Method 1. Mark both the Comma and Space under the Delimiters in Convert Text to Columns Wizard – Step 2 of 3.

You will see the separated columns.

Read More: How to Use Line Break as Delimiter in Excel Text to Columns


Practice Section

You can practice the explained methods with our downloaded file.

Practice Section to Convert Text to Columns in Excel with Multiple Spaces


Download the Practice Workbook


Related Articles


<< Go Back to Splitting TextSplit in ExcelLearn Excel

Get FREE Advanced Excel Exercises with Solutions!
Musiha Mahfuza Mukta
Musiha Mahfuza Mukta

Musiha Mahfuza Mukta is a marine engineer who loves exploring Excel and VBA programming. To her, programming is a time-saving tool for dealing with data, files, and the internet. She's skilled in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, and Excel & VBA, going beyond the basics. With a B.Sc in Naval Architecture & Marine Engineering from BUET, she's shifted gears and now works as a content developer. In this role, she creates techy content exclusively focused on Excel... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo