How to Press "enter' for a new line in a textbox?

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
hi,
I have a testbox1 in excel where after typing data in the text box i want to be able if required to press enter and start a new line in the textbox1, i am using the code below but i get an error please can you help me? thank you in advance.
Code:
Private Sub TextBox1_Change()
    If KeyCode = vbKeyReturn Then
        Me.NewLine
    End If
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Thnak you for your help, all sorted now many thanks :) code works great :)
 
Upvote 0
If you set the MultiLine and EnterKeyBehavior properties of the textbox to True all you need to do is press Enter.
 
Upvote 0
:) just tried that thank you thats great i tried this earlier but only changed the multiline to True and not the other, :) that is great thank you
 
Upvote 0
I always forget to change both too.:eek:
 
Upvote 0
Thats one to remember :) i am pretty new to this , still learning but enjoying it at the same time :)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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