entering multiple lines in a textbox

sepandb

Board Regular
Joined
May 25, 2009
Messages
141
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..
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

EducatedFool

Active Member
Joined
Jun 10, 2009
Messages
272
Try
Rich (BB code):
Private Sub CommandButton1_Click()
    [a2] = Replace(Me.TextBox1, vbCr, "")
End Sub
 

sepandb

Board Regular
Joined
May 25, 2009
Messages
141
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..
 

phxsportz

Well-known Member
Joined
Jun 11, 2006
Messages
1,985
Code:
Private Sub CommandButton1_Click()
    Cells(2, 1) = Replace(TextBox1.Value, VbCr,"")
End Sub
 
Last edited:

sepandb

Board Regular
Joined
May 25, 2009
Messages
141
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...
 

EducatedFool

Active Member
Joined
Jun 10, 2009
Messages
272
Try
Rich (BB code):
Private Sub CommandButton1_Click()
    [a2] = Replace(Me.TextBox1, vbCr, "")
    [a2].WrapText = True
End Sub
 

phxsportz

Well-known Member
Joined
Jun 11, 2006
Messages
1,985
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..
 

sepandb

Board Regular
Joined
May 25, 2009
Messages
141
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
 

Forum statistics

Threads
1,175,656
Messages
5,898,719
Members
434,724
Latest member
DJT

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
Top