Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: entering multiple lines in a textbox

  1. #1
    Board Regular
    Join Date
    May 2009
    Posts
    141
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default entering multiple lines in a textbox

    I have a textbox in my userform where anything typed in the box is entered into cell A2 in my worksheet. However, multiple lines of text are not properly displayed in my worksheet. I have enabled MultiLine and EnterKeyBehaviour in the properties window of the textbox so I can type multiple lines in my textbox. The problem is that when I press the button to enter the text from my txtbox to cell A2, the cell doesn't actually display the text in separate lines. It just places a square symbol in the place that enter should have been pressed and the text should have been split into separate lines.

    How can I get the separate lines of text in my textbox to be properly displayed in a cell? Thanks for your help in advance..

  2. #2
    Board Regular EducatedFool's Avatar
    Join Date
    Jun 2009
    Location
    Russia
    Posts
    272
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Try
    Code:
    Private Sub CommandButton1_Click()
        [a2] = Replace(Me.TextBox1, vbCr, "")
    End Sub

  3. #3
    Board Regular
    Join Date
    May 2009
    Posts
    141
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    No this doesn't seem to work. I seem to be getting the same problem, where cell A2 doesn't actually separate the lines of text the way it is separated in my textbox..

  4. #4
    Board Regular
    Join Date
    May 2009
    Posts
    141
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Could anybody help me out with this problem?

  5. #5
    Board Regular phxsportz's Avatar
    Join Date
    Jun 2006
    Location
    Phoenix, AZ
    Posts
    1,985
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Code:
    Private Sub CommandButton1_Click()
        Cells(2, 1) = Replace(TextBox1.Value, VbCr,"")
    End Sub
    Last edited by phxsportz; Jun 25th, 2009 at 02:45 PM.
    I used to have a Darkroom, Now I have a PC... And it smells better
    WWW.SPUDSBAR.COM

  6. #6
    Board Regular
    Join Date
    May 2009
    Posts
    141
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Quote Originally Posted by phxsportz View Post
    Code:
    Private Sub CommandButton1_Click()
        Cells(2, 1) = Replace(TextBox1.Value, VbCr,"")
    End Sub
    Thanks for the code. But this doesn't separate the lines of text if you write 2 lines in the textbox. It just shows one line of text separated by a strange square symbol where the space should have been...

  7. #7
    Board Regular EducatedFool's Avatar
    Join Date
    Jun 2009
    Location
    Russia
    Posts
    272
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Try
    Code:
    Private Sub CommandButton1_Click()
        [a2] = Replace(Me.TextBox1, vbCr, "")
        [a2].WrapText = True
    End Sub

  8. #8
    Board Regular phxsportz's Avatar
    Join Date
    Jun 2006
    Location
    Phoenix, AZ
    Posts
    1,985
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Quote Originally Posted by sepandb View Post
    Thanks for the code. But this doesn't separate the lines of text if you write 2 lines in the textbox. It just shows one line of text separated by a strange square symbol where the space should have been...
    Works for me... Strange Indeed..

    I'm using Excel 2003 though, not sure if that's an issue..
    I used to have a Darkroom, Now I have a PC... And it smells better
    WWW.SPUDSBAR.COM

  9. #9
    Board Regular
    Join Date
    May 2009
    Posts
    141
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: entering multiple lines in a textbox

    Quote Originally Posted by phxsportz View Post
    Works for me... Strange Indeed..

    I'm using Excel 2003 though, not sure if that's an issue..

    I am using 2003. Maybe the fact that I left out some details in my initial description changed a few things. The cell that I am pasting to is not static. Depending on how big my spreadsheet becomes, it is either higher or lower on the spreadsheet. It will always be in Column A, but the row number changes. I have a declared variable called Finalrow, which finds the last row of data in my spreadsheet. The cell that I want to paste to would be ("A" & Finalrow + 2), so 2 rows below my 'FINALROW'.

    I'm not sure if that changes anything. I assume the code you gave me should work despite this, as I modified the code appropriately.

    I enter text into my textbox, press enter to start another line and enter more text into the box. But when it gets pasted to the cell in the worksheet, it is all in one line. Hopefully this post has cleared a few things up.

    Thanks for all of your time already. I really appreciate it

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •