Requirement:
Is it possible to vertically center the text in a userform label?
For example: The user has a label that's 22px high, but the text is only 10pt
Solution:
Re: Vertically Center Text In Userform Label
The label control has no built in vertical alignment.
The simplest way is to use 2 labels. One displays the border at the required size.
The other is autosize to fit display text and then centered over the other label.
This code assume 2 labels on a userform
Label1 formatted to size of holding border.
Label2 to hold text and center both vertically and horizontally.
With Label2
.AutoSize = False
.Height = 100
.Width = 200
.Caption = "This is my" & vbLf & "label text"
.AutoSize = True
.Top = Label1.Top + ((Label1.Height - .Height) / 2)
.Left = Label1.Left + ((Label1.Width - .Width) / 2)
End With
Obtained from the OzGrid Help Forum.
Solution provided by Andy Pope.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to use a dropdown or text option |
How to copy cell value on Sheet 1 to a location in a text in another cell on Sheet 2 |
How to make all empty textboxes invisible |
How to add frequently used text to a cell |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.