Solved

How to force a new line in text box - Excel userform

Posted on 2012-03-25
3
505 Views
Last Modified: 2012-03-25
Hello,

I have a userform that I would like to display a string of text in. I have built the string using the code below:

Private Sub UserForm_Initialize()
Dim rngComments As Range
Dim strcombuild As String
Set rngComments = Range("Comments")
strcombuild = ""
    With Me
        .CommandButton1.Caption = "Close"
    End With

For Each rw In rngComments.Rows
        i = 1
        If rw.Columns(1).Value = TaskID Then
        
            For Each cl In rw.Cells.Columns
                    If i = 1 Then
                        strcombuild = strcombuild & rw.Cells(1, i).Value
                    Else
                        strcombuild = strcombuild & " - " & rw.Cells(1, i).Value
                    End If
                    i = i + 1
            Next cl
            strcombuild = strcombuild & "." & vbNewLine
        End If
Next rw
Me.Textbox1 = strcombuild
End Sub

Open in new window


When I set Textbox1=strcombuild, it just displays one continuous line of text with like a paragraph marker where the carriage / line return should be.

When I assign Label1=strcombuild it displays fine.

I would like to have the text displayed on multiple lines in Textbox1 - any help would be appreciated.

Thanks,

Craig
0
Comment
Question by:slobber72
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
Just set the .MultiLine property of your textbox to true, and then your vbnewline will be represented in the textbox.

See attached.

Dave
multilineTextbox-r1.xls
0
 

Author Comment

by:slobber72
Comment Utility
Thanks Dave. Much appreciated.
0
 
LVL 41

Expert Comment

by:dlmille
Comment Utility
my pleasure.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now