Reverse order of data in a cell
Reverse order of data in a cell
(OP)
I am trying to figure how to reverse data in a string located in a cell. The string elements are separated by commas. For example, the string is : US=country,State=NorthCarolina,City =Charlotte. I want to reverse it to read City=Charlotte,State=NorthCarolina,Country=US.
Thanks
Thanks





RE: Reverse order of data in a cell
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Reverse order of data in a cell
Function reverse(A As String)
Dim B(30)
A = A + ","
Do While Len(A) > 0
i = i + 1
num = Application.WorksheetFunction.Find(",", A)
B(i) = Left(A, num - 1)
A = Right(A, Len(A) - num)
Loop
For j = i To 1 Step -1
reverse = reverse + B(j) + ","
Next j
reverse = Left(reverse, Len(reverse) - 1)
End Function
RE: Reverse order of data in a cell
=RIGHT(B2,MATCH(",",MID(B2,LEN(B2)-ROW(INDIRECT("1:"&LEN(B2))),1),0))&","&MID(B2,FIND(",",B2)+1,FIND(",",B2,FIND(",",B2)+1)-FIND(",",B2))&LEFT(B2,FIND(",",B2)-1)
Here the text to reverse is in cell B2, and you enter the formula with the (Control + Shift + Enter) keys. And each time you edit this. You don't put in the curly {} Excel does this automatically if array entered.
Regards
Robert