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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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