V. Ulizko
V. Ulizko

Reputation: 29

How To Adjust Height of Text Box based on Length of Text/String

This is more of a conceptual problem. As it says in the title, I would like to create a Function or Sub-Module that is capable of taking text from a cell and putting it into a text box on a form; then, I would like the text box to adjust its height based on the length of the text in that cell. I have done some research without much success, except for some outdated posts. I wish to understand if you can compare the length of the string to the width of a text box numerically, or if there is a simple way to calculate the string's width. The font I am using is Tahoma size 10.

Thank you in advance for your response.

Upvotes: 2

Views: 4802

Answers (1)

dbmitch
dbmitch

Reputation: 5386

No need for function. Use what Excel provides

Right click | Format Shape | Text Box

Under Auto Fit section

Check "Resize Shape to fit text"

Uncheck "Allow text to overflow shape"

Edited for UserForm textbox

Set AutoSize = True

Set Multiline = True

Upvotes: 2

Related Questions