Consulting

Results 1 to 6 of 6

Thread: Solved: Text from mutliline txtbox to merged cell

  1. #1
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location

    Solved: Text from mutliline txtbox to merged cell

    I want the user to be able to use the enter button in a multiline textbox, which works fine.

    But when I send that data to a merged cell, Excel doesn't recognise the use of the enter button for a new line and creates a small square. The font is Arial but others produce same result.

    I know that you can use Alt+Enter in a cell but is there any way around this when sending the data?

    Basically I want the user to be able to type grammatically and be shown accordingly in the cell.

    I have also tried sending the text to a sheet textbox but that displays the line break as the new paragraph symbol.
    Last edited by pcsparky; 12-05-2009 at 11:18 AM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Got a small sample workbook?

    Paul

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Here's an example that I threw together. I see no squares in it.

    Maybe it's how you set the range value.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Have you tried replacing Chr(10) with Chr(13) or vice versa?

  5. #5
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location
    Thanks guys. The example xlsm wb didn't work as I could still see the squares. But I did use it to play around with alternatives.

    I did manage to sort it with a slight alteration to MikeRickson's suggestion. Replacing Chr(13) with Chr(10) produces two line breaks but does get rid of the squares.

    This does the trick though:

    Range("A1") = Replace(TextBox1.Text, Chr(13), "")

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi pcsparky,

    I see that you solved it, nicely done

    I believe that (leastwise in WIN) a hard return produced by using the Enter key whilst in a multiline textbox, produces a combination Chr(13) + Chr(10).

    Using Steve's example wb:
    [vba]Private Sub CommandButton1_Click()
    Range("A1") = Replace(TextBox1.Value, Chr(13), "")
    Unload Me
    End Sub[/vba]
    If you put a breakpoint at the top of the procedure, you will see two little squares (at ea hard return) while holding the cursor over Textbox1.Value; the first is the Chr(13), the second of course, the Chr(10).

    Have a great day :-)

    Mark

Posting Permissions

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