Results 1 to 8 of 8

TextBox on Userform carriage return/word wrap problem

This is a discussion on TextBox on Userform carriage return/word wrap problem within the Excel Questions forums, part of the Question Forums category; Hi: 2 Questions: I have a text box on a userform where I want to store comments that the user ...

  1. #1
    Board Regular
    Join Date
    Sep 2002
    Location
    Ontario
    Posts
    260

    Default TextBox on Userform carriage return/word wrap problem

    Hi:

    2 Questions:

    I have a text box on a userform where I want to store comments that the user can enter. The problem is, when I hit Enter after typing something into the textbox, , the cursor does not go to the next line, but instead the text box loses the focus, which instead goes to a button I've put on the form. I want to be able to enter text in paragraphs etc, so how can I do that? I can find no property of the text box from the Proerties Window which corresponds to this problem.

    Secondly, I want to be able to store this text from the userform on the worksheet. I discussed a few weeks ago the possibility of storing the comments as an Excel Comment, but someone suggested that I just store the text in a cell, particularly as I think comments have a limited capacity. Can I hold text in a cell and still retain the paragraphs etc? I also want to be able to allow the user to append to this comment. When an "Add Comment' button on the worksheet is clicked, the userform is loaded, and the text from the cell is placed into the text box, (hopefully with paragraphs intact), then the focus of the textbox go to the bottom of the text so far, so that additional comments can be made.

    Any help greatly appreciated.

    Overall, what I am trying to accomplish is to take a list of 2,000 clients, arranged in rows of course, and have ONE column devoted to storing these comments. The user will click on any cell in that particular client's row, then click 'Add Comment', and see the comments so far and append if necessary.

    Thanks.

  2. #2
    MrExcel MVP Tom Urtis's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, California USA
    Posts
    11,011

    Default Re: TextBox on Userform carriage return/word wrap problem

    To achieve the effect of creating new lines of text, "paragraph-looking" text, etc. in a TextBox when you hit Enter while entering text into a TextBox, set the TextBox's EnterKeyBehavior property to True *AND* set its MultiLine property to True.

    A comment can hold about 32,000 characters of text, or about 255 lines.

    You can enter the TextBox text into a cell like so:

    Private Sub CommandButton1_Click()
    Range("A1").Value = TextBox1.Text
    End Sub


    You can append an existing cell value with an added text like so:

    Private Sub CommandButton2_Click()
    Range("A1").Value = Range("A1").Value & TextBox1.Text
    End Sub


    You can populate a userform's TextBox with a cell's value like so:

    Private Sub UserForm_Initialize()
    TextBox1.Text = Range("A1").Value
    End Sub


    In the worksheet cell, you will see little squares that represent where the user hit the Enter key in the userform TextBox. Those are most likely ascii character 13 and normal given what you are asking for.

  3. #3
    Board Regular
    Join Date
    Sep 2002
    Location
    Ontario
    Posts
    260

    Default Re: TextBox on Userform carriage return/word wrap problem

    Thanks Tom.

    I had already set th emultiline property to true, but not the EnterKeyBehaviour.

  4. #4
    Board Regular Kris75's Avatar
    Join Date
    Jul 2009
    Location
    Kettering, Northamptonshire
    Posts
    143

    Default Re: TextBox on Userform carriage return/word wrap problem

    5 Years Later and that little Gem is still valuable

    thank you!
    Kris


    "If you do things right, people won't be sure you've done anything at all"

  5. #5
    New Member viktoryeung's Avatar
    Join Date
    Feb 2005
    Location
    Toronto
    Posts
    17

    Default Re: TextBox on Userform carriage return/word wrap problem

    It's the year 2011, and just confirming this hint is still useful!

  6. #6
    New Member
    Join Date
    Apr 2012
    Posts
    1

    Default Re: TextBox on Userform carriage return/word wrap problem

    I'm pleased to report Microsoft hasn't changed anything yet. Thanks! I needed this tip!

  7. #7
    Board Regular
    Join Date
    Apr 2010
    Posts
    151

    Default Re: TextBox on Userform carriage return/word wrap problem

    Sorry for bumping up the old thread but couldn't resist replying. It is still valid at onset of 2014

  8. #8
    New Member
    Join Date
    Oct 2014
    Posts
    3

    Default Re: TextBox on Userform carriage return/word wrap problem

    Oct 2014 !

    I couldn't resist joining and saying that this is still a really helpful little piece of information.

    It's simple things like this that are so hard to discover.

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
  •  


DMCA.com