Reverse list of words in a text string separated by comma

sounny

New Member
Joined
Feb 7, 2011
Messages
4
I have an excel spread sheet that has a column with lists in text format separated by comma. Each individual field has different amounts of word.

what I have

word1,word2,word3,word4

what I want

word4,word3,word2,word1

Some fields may have 4 words, other may have 6, other 10, etc.

Is there a formula that I can use to get this reversed?

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Use this code in a vba module</PRE>
</PRE>
Code:
[/B]</PRE>
[B]Function ReverseCell(Rcell As Range, Optional IsText As Boolean)[/B]	Dim i As Integer	Dim StrNewNum As String	Dim strOld As String	strOld = Trim(Rcell)	For i = 1 To Len(strOld)		StrNewNum = Mid(strOld, i, 1) & StrNewNum	Next i    	If IsText = False Then		ReverseCell = CLng(StrNewNum)	Else		ReverseCell = StrNewNum	End If[B]End Function
</PRE>Then Enter the function like this for text:

=Reversecell(A1,TRUE)

Or either of the ways below for numeric data

=Reversecell(A1,FALSE)
 
Upvote 0
Perhaps:

Code:
Function ReverseString(rngString As Range, Optional strDelim As String = ",") As String
    Dim vStrings As Variant, lngString As Long
    vStrings = Split(rngString, strDelim)
    For lngString = UBound(vStrings) To LBound(vStrings) Step -1
        ReverseString = ReverseString & strDelim & vStrings(lngString)
    Next lngString
    ReverseString = Replace(ReverseString, strDelim, "", 1, 1)
End Function

above stored in standard module in VBE then

Code:
=ReverseString(A1)

where A1 holds original
 
Upvote 0
Paste the below code in regular Module of Excel VBA.:

Public Function ReverseWords(cell As Range)

Dim InputStr As String
Dim InputArray() As String
Dim OutputArray As String
Dim WordsCount As Integer

InputStr = cell.Value

'Split all the words and put it
'in an array
InputArray = Split(InputStr, " ")
WordsCount = UBound(InputArray)

'Read all the words in reverse
'Order and return to function

For i = WordsCount To 0 Step -1
ReverseWords = ReverseWords & InputArray(i) & ", "
Next

End Function


Now Use the below UDF (User defined formula to reverse the words of a cell


=ReverseWords(Cell Address)


http://www.learnexcelmacro.com/2012/01/words-in-reverse-order/
 
Upvote 0
In what way is that better than DonkeyOte's post? Except that your post is nearly a year newer of course.
 
Upvote 0

Forum statistics

Threads
1,216,515
Messages
6,131,111
Members
449,621
Latest member
feaugcruz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top