textbox auto size

charly1

Board Regular
Joined
Jul 18, 2023
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi all

I'm sure my question has been asked and has a simple soution although i cannot seem to find one. Any help would be appreciated.

I have a textbox control in a user form with a set width of 188. I have set the multiline property to true.

I would like the textbox textbox width to remain fixed regardless of whether or how much text is entered by a user, however the textbox should auto size its height to accommodate text once a line is filled.

As an aside and if the above is possible would it then be possible to give the textbox a max height up to which it can auto size.

Thanks in advance!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Perhaps with code similar to this:
VBA Code:
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    With TextBox1
        .AutoSize = True
        .AutoSize = False
        .Width = 144
        If .Height > 100 Then .Height = 100
    End With
End Sub
 
Upvote 1
Solution
Splendid. Thanks so much.

Would you mind explaining though how this code actually works. I've been looking at it and can't for the life of me make sense of it. [Although it works perfectly].
 
Upvote 0
Well, it was a bit of trial and error to be honest :-) . I found that this sequence of steps gave most reliable results.
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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