Multiple cell values in one textbox

reshma

New Member
Joined
Dec 28, 2011
Messages
10
Hi,
I am trying to build a simple tool using an userform. I have my results as a range of cells A1:A10 in an excel sheet.
The result will be like:

1-1
2-4
5-8
8-8
9-14
14-14
15-16
17-19
20-21
22-23

But I want the result to be displayed in one textbox in userform.Is there any way?
 
This will join all the values in A1:A10 with a line break between each. simply use the string s to update the textbox value in your user form.
Code:
    Dim s As String, c As Range
    For Each c In Range("A1:A10")
        If s = "" Then s = c Else s = s & vbLf & c
    Next c
 
Upvote 0
Why not use a list box?

Code:
Private Sub UserForm_Initialize()
UserForm1.ListBox1.RowSource = Worksheets("sheet1").Range("A1:A10").Address(external:=True)
End Sub
 
Upvote 0
Welcome to MrExcel.

Set the TextBox's MultiLine property to True and try:

Code:
Private Sub UserForm_Initialize()
    Dim Cell As Range
    With ActiveSheet
        TextBox1.Text = .Range("A1").Text
        For Each Cell In .Range("A2:A10")
            TextBox1.Text = TextBox1.Text & Chr(10) & Cell.Text
        Next Cell
    End With
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top