Skip to main content

How to rearrange text in a cell in Excel?

Author: Siluvia Last Modified: 2024-11-20

Suppose you have a spreadsheet with a long list of names formatted as “Last name First name”, and now you need to rearrange all names to “First name, Last name”. How can you achieve this? This article introduces three methods to solve the problem.

Rearrange text in a cell with formula
Rearrange text in a cell with VBA code
Quickly rearrange text in a cell with Kutools for Excel


Rearrange text in a cell with formula

The below formula can help you flip last name and first name in a cell in Excel. Please do as follows.

1. Select a blank cell to output the rearranged text, enter the below formula into it and then press the Enter key.

=TRIM(MID(b2,SEARCH(" ",b2)+1,250))&" "&LEFT(b2,SEARCH(" ",b2)-1)

A screenshot showing a formula to rearrange text in Excel from Last name First name to First name Last name

Note: in the formula, B2 is the cell contains the name you will rearrange. Please change it based on your need.

2. Keep selecting the result cell, drag the Fill Handle down to flip all names as below screenshot shown.

A screenshot showing results of rearranging text using a formula in Excel


Easily rearrange text in a cell in Excel:

The Reverse Text utility of Kutools for Excel can help you to easily swap text around within one cell by certain separator in Excel. See below screenshot:

A screenshot of Kutools for Excel Reverse Text utility for rearranging text in a cell

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


Rearrange text in a cell with VBA code

Besides, you can apply below VBA code to flip all names in a list at once in Excel. Please do as follows.

1. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy below VAB code into the Module window.

VBA code: Rearrange text in a cell

Sub RearrangeText() 
'Updated by Extendoffice 20180503
Dim xRg As Range, yRg As Range 
Dim LastRow As Long, i As Long 
Dim strTxt As String, strFs As String 
Dim strLs As String, N As Integer 
On Error Resume Next 
Set xRg = Application.InputBox(Prompt:="Range Selection:", _ 
Title:="Kutools for excel", Type:=8) 
For Each yRg In xRg 
On Error Resume Next 
strTxt = yRg.Value 
Trim (strTxt) 
N = InStr(strTxt, " ") 
strLs = Left(strTxt, N - 1) 
strFs = Right(strTxt, Len(strTxt) - N) 
yRg.Value = strFs & " " & strLs 
Next 
End Sub

3. Then a Kutools for Excel dialog box pops up, please select the name list you want to rearrange, and then click the OK button. See screenshot:

A screenshot of the Kutools for Excel dialog box for selecting a range to rearrange text in Excel

Then all “Last name First name” entries in the selected list are flipped immediately.


Quickly rearrange text in a cell with Kutools for Excel

This section will introduce the Reverse Text Order utility of Kutools for Excel to help you rearrange text in a cell.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

1. Select the name list you will flip the “Last name First name”, then click Kutools > Text > Reverse Text Order. See screenshot:

A screenshot showing the Reverse Text Order option under the Kutools menu in Excel

2. In the Reverse Text dialog box, select the Space option and then click the OK button. See screenshot:

A screenshot of the Reverse Text dialog box in Kutools for Excel for rearranging text by space

Then all names in selected list are rearranged at once.

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!