Skip to main content

How to rearrange text in a cell in Excel?

Supposing you got a spreadsheet with a long list names which all format as “Last name First name”, and now you need to rearrange all names to “First name, Last name”. How to achieve it? This article will introduce three methods to help you 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)

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.


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:
Download and have try! (30-day free trail)


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:

Then all “Last name First name” in 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.

Before applying Kutools for Excel, please download and install it firstly.

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

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

Then all names in selected list are rearranged at once.

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


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...

Description


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!
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have text that needs swapping within a longer line,
E.G "The Quick Brown Fox Jumps Over The Dog Lazy" needs to read "The Quick Brown Fox Jumps Over The Lazy Dog" - would this work for swapping only the last two words?
This comment was minimized by the moderator on the site
I have 5 names separated by a comma inside of one cell. In a 2nd cell, I have the same names separated by commas sorted in a different order. Can Kutools allow you to sort the 5 items within the same cell alphabetically?
This comment was minimized by the moderator on the site
Hi Angel,
Kutools can't handle this kind of operation yet.
This comment was minimized by the moderator on the site
What do you do with three names?
This comment was minimized by the moderator on the site
Hi,
The methods also work for three names.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations