Carriage Return Characters - Chr(10)

A

AussieDave

Each data cell has multiple lines, delineated by a Chr(10) , which
looks perfectly good on the worksheet. However, when initialising a
UserForm with this data, each Chr(10) is duplicated. This only
becomes apparent when I save the data from the Form back to the
worksheet and can then see the superfluous Chr(10) shown as a small
box at the end of each line of data. Hoping someone can help me get
rid of the extra ones. Thanks in advance, Dave.
 
J

Joel

You need to adjust the width of the column. One return is being caused by
the chr(10), and the other return is due to the column width being too narrow
for the data and th eline is wrapping.
 
A

AussieDave

Thanks Joel, but that's not the case here. Even when a Chr(10) has
been inserted just to get a blank line, the duplication is still
occurring.
Dave
 
J

Joel

Are you gewtting two lines or three lines when you put chr(10) into the form?
You should get two because you start with one Line and putting the chr(10)
creates a second line.
 
D

Dave Peterson

I put a couple of buttons and a textbox on a small userform.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
With Worksheets("Sheet1").Range("b1")
.WrapText = True
.Value = Replace(Me.TextBox1.Value, vbCr, "")
End With
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.TextBox1
.MultiLine = True
.WordWrap = True
.EnterKeyBehavior = True
.Value = Worksheets("Sheet1").Range("A1").Value
End With
End Sub
 
D

Dave Peterson

I want to keep the linefeeds so the text wraps in the cell. I want to remove
the carriage returns so I don't see those little square characters.

That's why I used:
..Value = Replace(Me.TextBox1.Value, vbCr, "")
 
A

AussieDave

Thanks Dave - as usual, you're right on the button, it works
perfectly.

Thanks also to all others who contributed. Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top