×

How To Vertically Center A Userform Textbox

By Chris Newman •  Updated: 10/28/18 •  3 min read
Vertically Center Excel Userform Textbox Text

There’s No Middle Alignment Option…

Let’s just get straight to the point….unfortunately for some (lame) reason, Microsoft did not give us the option to middle align text within our Userform textbox controls. This can lead to some sloppy-looking interfaces (see the userform on the left below). But fear not, with a little bit of creativity, we can get the look and feel our userforms deserve!

Steps to middle align Excel Userform Textbox

Step 1: The Overlay

The essence of the trick is going to rely on overlaying one textbox on top of another one. So first, make a copy of your textbox and resize the height to the height of your textbox font size. Please note, I will be referring to the “original” textbox and the “new” textbox throughout these steps.

Steps to middle align Excel Userform Textbox

Step 2: Alignment

Next, you will want to center and middle align your New Textbox with your original one. To ensure that your Original Textbox does not move, select it last (while holding the Ctrl key). You will know your selection is correct if your Original Textbox has white boxes around it instead of black (shown below).

With both textboxes selected, proceed to right-click your mouse and navigate to the Align options and select both Middle and Centers. This will ensure you have perfect alignment.

Steps to middle align Excel Userform Textbox

Step 3: Remove Sunken Effect

Next, we will do some manipulation to “hide” the New Textbox. Select your New Textbox and go into its Properties (keyboard shortcut F4 to make appear). Scroll down to the SpecialEffect property and change it to 0 - fmSpecialEffectFlat.

How To Center Align Spreadsheet Userform Textbox Control

After doing this you may notice that the New Textbox is covering up the right/left edges of the Original Textbox’s border. To fix this, just bring in the sides of your New Textbox a bit until it is no longer covering any border.

How To Center Align Spreadsheet Userform Textbox Control

Step 4: A Couple Finishing Touches

If you go to test your userform now, you might notice a couple of things:

  1. There is an indentation in your text
  2. It may still be possible to select the textbox in the background (aka Original Textbox)
How To Center Align Spreadsheet Userform Textbox Control

Fix Indentation - Select your New Textbox and change the SelectionMargin property to False

Fix Selection Issue - Select your Original Textbox and change the Enabled property to False

Vertically Align Textbox Text In Userform
Vertically Align Textbox Text In Userform

You’ve Done It!

You have now completed the steps to stick it to Excel and show that you can really do anything you want inside this amazing program. If you have any questions, ideas, or need further clarification let me know if the comments section below.

Vertically Align Textbox Text In Userform

Download The Excel Example File

If you would like to get a copy of the Excel file I used throughout this article, feel free to directly download the spreadsheet by clicking the download button below.

Keep Learning

Chris Newman

Chris Newman

Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.