How to remove trailing Chr(10) character from a string

RunTime91

Active Member
Joined
Aug 30, 2012
Messages
290
Office Version
  1. 365
Greetings All ~

I absolutely cannot believe I'm here asking how to do this but Google has no clue

The setup is simple - I'm looping through a listbox and placing each selected item in one cell on an excel sheet.
I'm using Chr(10) to stack them atop one another. What I'm trying to do is simply remove the trailing Chr(10) character once all the values are entered into the cell

Code:
Dim Rng As Range
Dim Str As String

Set Rng = ThisWorkbook.Sheets("Checklist").Range("G2")
Str = Rng.Value

For p = 0 to UserForm.LstSusRsns.ListCount -1
If UserForm.LstSusRsns.Selected(p) = True Then
ThisWorkbook.Sheets("Checklist").Range ("G2") _
= ThisWorkbook.Sheets("Checklist").Range ("G2") _
& UserForm.LstSusRsns.Selected.List(p, 0) & Chr(10)

'This is one of probably 10-12 trys and my latest failure which brought me here
Rng.Value = Trim(Rng.Value)

In the immediate window ?Rng is showing the cell value but for some reason the Trim is not working
I have tried If statements (which I don't think would not be necessary here because the trailing Chr(10) will always be present
I have tried RTrim; Right; Left; LTrim and WouldYouPleaseForLoveOfGodWorkTrim et al.

And here I am...

As Always Thank You for any assistance...

RT 91
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Have you tried:
rng.value = left(rng.value,len(rng.value)-1)
I did... But, I wrote it like this --> Rng.Value = Left(Rng.Value, Len(Rng.Value), -1) (or a any number of other incorrect ways)

The correct way, which you have posted here - Works like a Dream!!

Thank You, CandyMan!!
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,507
Members
452,194
Latest member
Lowie27

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