Excel VBA - carriage returns

  • Thread starter Thread starter KD
  • Start date Start date
K

KD

Hi,

I am writing some vba code to split up some text that has
been entered in textboxes, and in every case there appears
to be carriage returns at the end of each line. Is there
a way I can strip out each line and store it in to a
seperate variable (eg line1,line2,line3 and line4 - there
are a maximum of 4 lines per textbox)?

Many thanks
KD
 
Hi KD

Linebreaks are either Ascii 10 or Ascii 13 or combinations of the two. If
you use Excel 200 or above on Windows, try Replace:

Sub test()
Dim S As String
S = "Hello" & vbNewLine & _
"world" & Chr(13) & _
"how" & vbCrLf & _
"are" & Chr(10) & "You?"
MsgBox S
S = Replace(S, Chr(10), " ")
S = Replace(S, Chr(13), " ")
S = Replace(S, " ", " ")
MsgBox S
End Sub

HTH. Best wishes Harald
 

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

Back
Top