View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default CRLF in text box

Your code worked fine for me. (changed userform to userform1)

--
Regards,
Tom Ogilvy

Neil Miller wrote in message
m...
Can anyone explain the following behaviour, or perhaps more likely,
tell me what I'm doing wrong? I thought I had done this many times
before

Set up a Userform with a textbox, e.g. TextBox1, that has both
EnterKeyBehavior and MultiLine set to True. Enter a single character
followed by a Return - the textbox should then contain, for example:
"aCRLF"

Now, if I want to remove the CRLF, I have been using:

With UserForm
Do While Right(.TextBox1.Text, 2) = vbCrLf
.TextBox1.Text = LeftB(.TextBox1.Text, Len(.TextBox1.Text) - 2)
Loop
End With

Now, this code loops, because when I examine the results of the Left
(or LeftB - the results are the same) function, .TextBox1.Text still
contains the CRLF. The only way I can get it to work is to store the
original text, set .TextBox1.Text to "", and then store the results of
the Left function back in the textbox.

What is happening here? It's an easy bypass, but I may have used this
technique elsewhere and would like to know whether I need to change
other instances of this type of code.

Excel version is 2002 running on XP professional.

Many thanks in advance for any help received.

Neil