Read column right-to-left

tvisgod

New Member
Joined
Jul 20, 2011
Messages
18
I'm hoping for help crafting a function to apply to all the cells (containing entries of various lengths) in a column.
The function should "read" the characters in a cell Right-to-Left, searching for a particular sequence. In my case the sequence is kay-space-semicolon. In other words...
; K (left to right)
or
K ; (if read right to left)
The function would eliminate everything left of the K (including the semicolon and the space) when this sequence is found. If the sequence is not found, the cell remains as normal.
Example: as;lk djf 83; K;lasd K would return K;lasd K

Any help would be appreciated. Thank you.
 
=IF(COUNTIF(A1,"*; K*"),"K"&TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"; K",REPT(" ",200)),200),200)),A1)

The above function is working great for me. Is there any way to incorporate another step? After this function has been applied (everything left of the last K sequence has been removed), I'd like to remove any remaining sequences in the string that begin with a semicolon.

For example, if after applying the above function, I'm left with a string like this:
K2837 .b80 830; jsf9 kdf 9h. ajsdf0
I'd like to adjust the function so it eliminates ; jsf9 kdf 9h. ajsdf0 and leaves K2837 .b80 830

Should I just do this as a separate function? Or is there a way to incorporate it into =IF(COUNTIF(A1,"*; K*"),"K"&TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"; K",REPT(" ",200)),200),200)),A1)
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

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