Reverse the Word Order within a Text String in One Cell

,

This post will guide you how to reverse the word order within a text string in one cell in Excel. How do I reverse list of words in a text string separated by space character with VBA Macro in Excel.

Reverse Word


If you want to reverse the word order in a text string in one cell, you can use the following VBA Macro to achieve the result. Just do the following steps:

#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module.

convert column number to letter3

#4 paste the below VBA code into the code window. Then clicking “Save” button.

reverse word1

Sub ReverseWord()
Dim cel As Range
Dim sourceRange As Range
Set sourceRange = Application.Selection
Set sourceRange = Application.InputBox("Select the Range of cells to be reversed", "reverse string", sourceRange.Address, Type:=8)
delmiter = " "
For Each cel In sourceRange
    strList = VBA.Split(cel.Value, delmiter)
    xOut = ""
    For i = UBound(strList) To 0 Step -1
        xOut = xOut & strList(i) & delmiter
    Next
    cel.Value = xOut
Next
End Sub

#5 back to the current worksheet, then run the above excel macro. Click Run button.

reverse word2

#6 Select the Range of cells to be reversed

reverse word3

#7 let’s see the result.

reverse word4

 

Leave a Reply