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.
#2 then the “Visual Basic Editor” window will appear.
#3 click “Insert” ->”Module” to create a new module.
#4 paste the below VBA code into the code window. Then clicking “Save” button.
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.
#6 Select the Range of cells to be reversed
#7 let’s see the result.
Leave a Reply
You must be logged in to post a comment.