Note: The other languages of the website are Google-translated. Back to English

How to reverse text string or words order in Excel?

When you use the Excel worksheet, how do you reverse the text string or words order in Excel? For example, you want to reverse “Excel is a useful tool for us” to “su rof loot lufesu a si lecxE”. Or sometimes you may reverse the words order such as “Excel, Word, PowerPoint, OneNote” to “OneNote, PowerPoint, Word, Excel”. Normally this is somewhat difficult to solve this problem. Please look at the following methods:

Reverse text string with User Defined Function

Reverse words order separated by specific separator with VBA code

Reverse text string or words order with Kutools for Excel quickly and easily


arrow blue right bubble Reverse text string with User Defined Function

Supposing you have a range of text strings which you want to reverse, such as “add leading zeros in Excel” to “lecxE ni sorez gnidael dda”. You can reverse the text with following steps:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Modulewindow.

Function Reversestr(str As String) As String
    Reversestr = StrReverse(Trim(str))
End Function

3. And then save and close this code, go back to the worksheet, and enter this formula: =reversestr(A2) into a blank cell to put the result, see screenshot:

4. Then drag the fill handle down to copy this formula, and the text in the cells is revered at once, see screenshot:


arrow blue right bubble Reverse words order separated by specific separator with VBA code

If you have a list of cell words which are separated by commas as this “teacher, doctor, student, worker, driver”, and you want to reverse the words order like this “drive, worker, student, doctor, teacher”. You can also use follow VBA to solve it.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Module window.

Sub ReverseWord()
'Updateby Extendoffice
Dim Rng As Range
Dim WorkRng As Range
Dim Sigh As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Sigh = Application.InputBox("Symbol interval", xTitleId, ",", Type:=2)
For Each Rng In WorkRng
    strList = VBA.Split(Rng.Value, Sigh)
    xOut = ""
    For i = UBound(strList) To 0 Step -1
        xOut = xOut & strList(i) & Sigh
    Next
    Rng.Value = xOut
Next
End Sub

3. Then press F5 key, a dialog is displayed, please select a range to work with. See screenshot:

4. And then press Ok, another dialog is popped out for you to specify the separator that you want to reverse the words based on, see screenshot:

5. Then click OK, and you can see the words selected are reversed, see screenshots:


arrow blue right bubble Reverse text string or words order with Kutools for Excel quickly and easily

The Kutools for Excel’s Reverse Text Order can help you quickly and conveniently to reverse various text strings. It can do following operations:

Reverse the text from right to left, such as “tap some words” to “sdrow emos pat”;

Reverse the text are separated by space or other specific characters, such as “apple orange grape” to “grape orange apple”;

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days

Reverse the text from right to left:

1. Select the range that you want to reverse.

2. Click Kutools > Text Tools > Reverse Text Order, see screenshot:

3. In the Reverse Text dialog box, select the proper option from Separator which are corresponding with the cell values. And you can preview the results from the Preview Pane. See screenshot:

 Download and free trial Kutools for Excel Now !


Reverse the text are separated by space or other specific characters:

This feature also can help you to reverse the text strings which are separated by specific characters.

1. Select the cells and apply this utility by clicking Kutools > Text > Reverse Text Order.

2. In the Reverse Text dialog box, choose the separator which separate the cell values that you want to reversed the words based on, see screenshot:

3. Then click Ok or Apply, the words in the cells have been reversed at once. See screenshots:

Note:Checking Skip non-text cells to prevent you reversing the numbers in selected range.

To know more about this function, please visit Reverse Text Order.

Download and free trial Kutools for Excel Now !


arrow blue right bubble Demo: Reverse text string based on specific separator with Kutools for Excel

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Related article:

How to flip the first and last name in cells in Excel?


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom

 

Comments (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is absurd. So much code to perform just a simple task of reversing the string? :o Just 3 line function needs to be added in the module as below: Function strrev(strValue As String) strrev = StrReverse(strValue) End Function Now the formula =strrev(A1) can be used in Excel sheet. This works since StrReverse is an inbuilt function of VBA. :D
This comment was minimized by the moderator on the site
Another one... Function InvertText(str As String) 'By Faseeh Muhammad Dim m As Integer For m = Len(str) To 1 Step -1 countRepp = countRepp & Mid(str, m, 1) Next m End Function
This comment was minimized by the moderator on the site
Sorry a little editing Function InvertText(str As String) 'By Faseeh Muhammad Dim curr As String Dim m As Integer For m = Len(str) To 1 Step -1 countRepp = countRepp & Mid(str, m, 1) Next m Inverttext End Function
This comment was minimized by the moderator on the site
Hi all, i've tried this function: Sub ReverseText() 'Updateby20131128 Dim Rng As Range Dim WorkRng As Range On Error Resume Next xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) For Each Rng In WorkRng xValue = Rng.Value xLen = VBA.Len(xValue) xOut = "" For i = 1 To xLen getChar = VBA.Right(xValue, 1) xValue = VBA.Left(xValue, xLen - i) xOut = xOut & getChar Next Rng.Value = xOut Next End Sub but when i've ran it with numbers it has deleted all the zeros. do you know a function that not delete zeros? Thanks!!
This comment was minimized by the moderator on the site
Use Vineet's function code as a module and when using the formula, use this trick: =strrev(""&D9&"") where D9 contains the number. Vineet's VBA code for that function is: Function strrev(strValue As String) strrev = StrReverse(strValue) End Function
This comment was minimized by the moderator on the site
Use this..put your input in A1 then the output will be in B1 Sub zzzText() Dim xlen, xvalue, xoutput xlen = VBA.Len(Range("A1")) xvalue = Range("A1").Value xoutput = "" For i = 1 To xlen GetText = VBA.Right(xvalue, 1) xvalue = VBA.Left(xvalue, xlen - i) xoutput = xoutput & GetText Next i Range("B1").Value = xoutput Range("C1").Value = xlen Range("D1").Value = xvalue End Sub
This comment was minimized by the moderator on the site
I notice a lot of people are re-inventing the wheel by doing left, right commands, VB6 supports string reverse SYNTAX: strRevese("String") thats all you need Dim stCellValue, i For i = 1 To 5 Range("A" & X).Select stCellValue = Range("A" & X).Value stCellValue = StrReverse(stCellValue) Range("A" & X).Value = stCellValue Next i Another nifty trick would be to pre-populate zeros, if values under 10 but need to be in a time format such as "10:01:24" rather than "10:1:24" intMins = 1 stMinutes = right("00" & intMins, 2) result = 01
This comment was minimized by the moderator on the site
thank you its really useful for me :roll:
This comment was minimized by the moderator on the site
Hi I would like to reverse Dates. 20/11/2015 to 2015/11/20 Any Help? Thanks
This comment was minimized by the moderator on the site
For dates all you need to do is change the format of the cell to the format needed. Right click on the cell you would like to reverse and select format cell. Select Date under the category section and change the location from wherever you are to US or Czech or another country that may use the format you are interested in. Then pick the one that matches your requirements.
This comment was minimized by the moderator on the site
hi all, i don't have Kutools to reverse a character of text, if anybody has this tools and want to help me, please send me email to send my file to you for reverse. my email is: [b][b]mohanned1@windowslive.com[/b][/b] with regards,
This comment was minimized by the moderator on the site
please go through the instructions give by the extend office website after searching with google by reverse string in excel.
This comment was minimized by the moderator on the site
It's possible to reverse text using formula, it is repetitive and limited to how far you are prepared to go and subject to number of characters excel will allow in the formula bar. Max length of text will be 30 chars and is in cell A1. Cell B1 would read: =TRIM(MID(LEFT(A1&REPT(" ",31),31),30,1)&MID(LEFT(A1&REPT(" ",31),31),29,1)&MID(LEFT(A1&REPT(" ",31),31),28,1)&MID(LEFT(A1&REPT(" ",31),31),27,1)&MID(LEFT(A1&REPT(" ",31),31),26,1)&MID(LEFT(A1&REPT(" ",31),31),25,1)&MID(LEFT(A1&REPT(" ",31),31),24,1)&MID(LEFT(A1&REPT(" ",31),31),23,1)&MID(LEFT(A1&REPT(" ",31),31),22,1)&MID(LEFT(A1&REPT(" ",31),31),21,1)&MID(LEFT(A1&REPT(" ",31),31),20,1)&MID(LEFT(A1&REPT(" ",31),31),19,1)&MID(LEFT(A1&REPT(" ",31),31),18,1)&MID(LEFT(A1&REPT(" ",31),31),17,1)&MID(LEFT(A1&REPT(" ",31),31),16,1)&MID(LEFT(A1&REPT(" ",31),31),15,1)&MID(LEFT(A1&REPT(" ",31),31),14,1)&MID(LEFT(A1&REPT(" ",31),31),13,1)&MID(LEFT(A1&REPT(" ",31),31),12,1)&MID(LEFT(A1&REPT(" ",31),31),11,1)&MID(LEFT(A1&REPT(" ",31),31),10,1)&MID(LEFT(A1&REPT(" ",31),31),9,1)&MID(LEFT(A1&REPT(" ",31),31),8,1)&MID(LEFT(A1&REPT(" ",31),31),7,1)&MID(LEFT(A1&REPT(" ",31),31),6,1)&MID(LEFT(A1&REPT(" ",31),31),5,1)&MID(LEFT(A1&REPT(" ",31),31),4,1)&MID(LEFT(A1&REPT(" ",31),31),3,1)&MID(LEFT(A1&REPT(" ",31),31),2,1)&MID(LEFT(A1&REPT(" ",31),31),1,1)) Result: A1: Duncan Sullivan-Shaw B1: wahS-navilluS nacnuD Basically your text in cell A1 becomes 31 characters long by adding enough spaces to enable this, and each character is read singularly from right to left until you reach the first character. This will result in your reversed text containing leading spaces, which the TRIM command removes for you. To reduce or increase the length you would remove or add each statement. The number within the REPT statement should be 1 more than the maximum length you are working to and your first MID statement will start at the maximum length working down to 1.
This comment was minimized by the moderator on the site
I found that the original Sub gave out the results with additional sigh at the end of all selected cells. So I fixed this part. For i = UBound(strList) To 0 Step -1 If i > 0 Then xOut = xOut & strList(i) & Sigh Else xOut = xOut & strList(i) Next Rng.Value = xOut
This comment was minimized by the moderator on the site
Is it possible to start the reverse at a certain character length (for the user-defined function or VBA code)? For example, reverse cell A1 values starting after the character count equal to B1 value. So if B1 is 10 characters reverse will start at characters 11+ in A1..
This comment was minimized by the moderator on the site
Thank you very much. This code helped my friend in a very good way
This comment was minimized by the moderator on the site
awesome very helpful thanks for sharing the details
This comment was minimized by the moderator on the site
This is truly a great help ... Thank you so much
This comment was minimized by the moderator on the site
Ik zoek een manier om een heleboel woorden in 'rijm-fabetische volgorde' te zetten. Dus de laatste letters van het woord moeten in alfabetische volgorde. Iemand enig idee? VrGr Amanda
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations