How to reverse a string in Excel?

0

0

Is there an Excel function (or macro) I can use to reverse a string. i.e. to turn these words into sdrow eseht?

Here is why I need that:

My strings are similar to John|XYZ Street|215|USA and I need to find the text after LAST | character.

So, I thought about reversing the string to locate the text before the FIRST | in that. If anyone knows any other way to find the LAST |, it can be a useful solution.

Note 1: the number of | varies from string to string; so, searching for the 3rd | will not work.

Note 2: I know the text-to-columns button, but I can't use it, since it would affect all the structure of my sheet.

Marcelo

Posted 2019-08-12T13:34:49.530

Reputation: 23

My strings are similar to "John|XYZ Street|215|USA" and I need to find the text after LAST "|" character. So, I thought about revert the string and locate the text before the FIRST "I" in that. If anyone knows any other way to find the LAST "|", it can be a useful solution. Note 1: the number of "|"s varies from string to string; so, search for the 3rd "|" will not work. Note 2: I know the text-to-columns button, but I can't use it, since it would affect all the structure of my sheet. – Marcelo – 2019-08-12T13:40:55.317

1Quite some relevant information you got there in this comment. I suggest you edit your question to include all of that for future reference and to enhance the quality of your question. – JvdV – 2019-08-12T13:50:10.120

1Your actual requirement is hiding in a transient comment. You're asking something totally different as a way to eventually get to what you need (after applying more formulas to unravel it). What's in the question is a bad approach, but what you explain in your comment is very doable, several different ways. JvdV's answer may attract downvotes, even though it solves your problem, because it answers the comment but is totally unrelated to the question. Please do yourself and everyone who may try to answer a favor, and rewrite the question to contain essentially what's in the comment. – fixer1234 – 2019-08-13T05:32:51.363

Possible duplicate of Any Excel function that will reverse a string?

– fixer1234 – 2019-08-13T07:12:04.703

What you ask in the question has already been asked and answered (see proposed duplicate), so the question is likely to be closed as-is. That would be another reason to put your actual problem in the question. – fixer1234 – 2019-08-13T07:15:39.213

@fixer1234,, this edited version is almost similar,, which creates lots of confusion for the readers,, since OP demands to crack two different issues !! Now,, which answer should be appreciated,, since I've solved the first part & JvdV solves the second one? – Rajesh S – 2019-08-13T07:32:03.263

@Marcelo,, better you decide that which one is the core issue, since both are totally different,, better pick one you need or [Edit] your post & write that you need both to solve,, if you need so !! – Rajesh S – 2019-08-13T07:36:44.600

@RajeshS, It's even worse than you realized. The original question is a dupe. If you go there, that already has your answer. In fact, Gangula posted it here before you and then deleted his answer. – fixer1234 – 2019-08-13T07:40:20.037

@fixer1234,, yes you are write,,,I've to clean the desk ☺ – Rajesh S – 2019-08-13T07:48:35.083

Thank very much to all comments and to JvdV solution. And sorry for the unwanted confusion (I searched for "reverse string in Excel" but didn't found that other topic).. – Marcelo – 2019-08-13T14:11:11.737

Answers

3

Here is an option:

enter image description here

Formula in B1:

=TRIM(RIGHT(SUBSTITUTE(A1,"|",REPT(" ",LEN(A1))),LEN(A1)))

It's basically a small adaptation from this source's explanation on how to find a cell's "last word". I just swapped the spaces in a normal sentence with a pipe symbol in your case.


Of topic since you techniqually are not asking for it, but to reverse a text string, you could look into that same website's explanation on how to do that.

JvdV

Posted 2019-08-12T13:34:49.530

Reputation: 1 371

OP is expecting to reverse the order of the text string like the link shows explanation,, but your answer is different !! I think you need to correct it. – Rajesh S – 2019-08-13T06:19:48.387

@rajeshS, thanks for the comment, but I based my answer purely on further explanation by OP in his comments below the original question. – JvdV – 2019-08-13T07:05:03.093

it's the big mess,, OP has twisted the question without modify original post,,!! – Rajesh S – 2019-08-13T07:13:56.497