Formula Help

Antriksh5956

New Member
Joined
Sep 28, 2017
Messages
1
I have this formula and i know what it does but i am not able to understand how it works.

=TRIM(RIGHT(SUBSTITUTE(TRIM(A1)," ",REPT(" ",255)),255))

i am confused as how this formula works and what is the role of "255" in this ?


Thank You!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the MrExcel board!

As you know, the formula extract the last "word" from a cell value. By "word" I mean whatever comes after the last space character.

Since we do not know how long the word is going to be we first use TRIM to make sure there are no trailing spaces and then replace all the spaces with 255** spaces.
Then take the right 255 characters. That must give you the last "word" (assuming it is less than 255 characters long :) ) with a whole bunch (but exact number unknown) of space characters in front of it.
Finally, TRIM removes those leading spaces leaving you with that last "word" only.

** There is nothing special about the 255 (historically I think there was). The lower number the better (for efficiency) but does need to be a number that is larger than the longest "word" you expect to get at the end of a cell.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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