×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Reverse order of data in a cell

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

RE: Reverse order of data in a cell

You might try using the Split function to separate the entries by the comma, and then rebuild the string by walking the array from UBound to LBound.

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

Could use VBasic function, am sure you could optimise code but here is one solution :

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

You could also use an array entered formula:

=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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources