remove trailing returns from a string

reedssr

New Member
Joined
Feb 11, 2005
Messages
27
Rtrim does not work to do this and i have other returns in the text i do not want to remove. I tried using replace and specifying the start location, but it cut the entire string and only ended up being the length from where I specified to start the replace from. I haven't done a ton of string manipulation in VBA, i know how i could do this in several other languages, but does anyone know how to do it in vba?
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

reedssr

New Member
Joined
Feb 11, 2005
Messages
27
yes, it only trims white space, white space being spaces, not carriage returns or which charachter chr(10) is. I was thinking of using instr then mid to trim off the railing return chars
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
FWIW, my approach would be similar, but not quite the same: search(char(10),A1) and left(a1,....

You don't have to use VBA for this; I refrain from VBA when an on-sheet solution is available.

Nonetheless, McRitchie's work is fine, if you do go that way.
 

reedssr

New Member
Joined
Feb 11, 2005
Messages
27
i got it to work by using instr and mid to check just the first or last charachter and if it was chr(10) then do a mid on it, thanks for the other suggestions
 

Watch MrExcel Video

Forum statistics

Threads
1,127,529
Messages
5,625,351
Members
416,096
Latest member
forevans

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
Top