Add Text to UserForms and Labels

Add to Favorites
Author: don | Edits: don

Multiple methods for adding text to a UserForm via a Label.

This includes a simple way to add basic text and a way to add a lot of text, including new lines.

Sections:

Add Text to a UserForm

Add Text using VBA

Multiple Lines of Text in a Label

Add Text from the Worksheet

Notes

Add Text to a UserForm

A Label is the control that you use to add text to a UserForm. 

Click the UserForm and look to the Toolbox (go to View > Toolbox if you don't see it).

Click the A in the toolbox.

3cf2ac19281194efe6d30a965fdbdf9b.jpg

Once you click the A, go to the form and click and drag until a label appears.

b6da001aa9ad41e7581fceefe5a54d91.png

To learn more about this procedure, view our tutorial on adding controls to UserForms.

Add the Text

Once you have the label, look to the Properties window and change the Caption property. This controls what text appears in the label. If you don't see the properties window, make sure you clicked the Label and hit F4.

36d2dfe41fbb562c4b17d3d512250dd4.png

This is the simplest way to add text to a UserForm.

You may have noticed in other examples that the text looks different than this default text; to change the appearance, adjust the Font property.

Add Text using VBA

We can also add text to a Label using VBA, and this makes it a bit easier to add more text.

The above method works great for small amounts of text, but it can be really annoying to manage a larger section of text or when you want to add multiple separate lines to a Label; this section solves that problem.

Where to Add the Text

The text is added in the UserForm_Initialize event. In the VBA Project window, right-click the desired UserForm and click View Code.

b3c58e982c8bede210db9abb7d35ba9e.jpg

In the window that opens look for a section titled UserForm_Initialize(). If you don't see this section, look to the drop-down menus at the top of the window and select UserForm from the left one and Initialize from the right one. This section of code is what is run when the form opens.

fa47e90dfad1bf2e3c900ab4b9365c26.png

How to Add the Text

Label1.Caption = "Hi there!"

Label1 is the name of the label. You can see this when you click the label and look to the (Name) section of the Properties window.

Caption tells the form to add text to the label.

Everything in the quotation marks is what you want to add to the label.

e46157067fec866deaf2692af5b92113.png

The next section shows you how to add multiple lines of text.

Multiple Lines of Text in a Label

VBA allows us to add multiple lines, which adds a bit more formatting to the Label.

Label1.Caption = "Hi there!" & vbNewLine & "More stuff."

vbNewLine adds the new line.

& goes before and after the vbNewLine part and each section of text must be enclosed with quotation marks.

Here is the result:

cb2e54ceb331812fc185587d38411743.png

By keeping the contents of the label within the code window for the UserForm, you can add new lines and also manage the text much more easily.

You can also use this method to add text to a label from the worksheet.

Add Text from the Worksheet

You can add text from the worksheet with ease, simply follow the above examples and add some additional code to get a value from Excel.

Label1.Caption = Sheets("Sheet1").Range("A8").Value

Label1 is the name of the Label.

Sheets("Sheet1").Range("A8") is the address of the cell that contains the text to put into the Label. Sheet1 is the name of the worksheet and A8 is the cell.

Notes

For small amounts of text, you can use the Caption property from the Properties window; for large amounts of text, or, if you want to make more dynamic sections of text, use a little VBA and it will make your life much easier.

Make sure to download the attached sample file to see these example in Excel. Some examples have been commented out, but they are still there and you can see them and work with them by uncommenting them.

Question? Ask it in our Excel Forum


Downloadable Files: Excel File

Similar Content on TeachExcel
How to Add Formatting to Cells and Data in Excel Styles, Fonts, Colors, & More
Tutorial: In this tutorial I will cover how to use the various formatting tools in Excel. The Format...
Convert Numbers Stored as Text to Numbers in Excel
Tutorial: I'll show you 4 ways to convert numbers stored as text to numbers in Excel.  This situati...
Simple Alternatives to UserForms
Tutorial: This tutorial covers a few simple ways to show pop-up windows to users that allows you to ...
How to Create and Manage a Chart in Excel
Tutorial: In this tutorial I am going to introduce you to creating and managing charts in Excel. Bef...
Add Values to a ComboBox
Tutorial: Add values to a ComboBox in a UserForm in Excel. There are 3 simple ways to add values, tw...
Add Values to a ListBox
Tutorial: How to fill a Listbox with values in a UserForm. By default, a Listbox in a form will be e...
Tutorial Details
Downloadable Files: Excel File
Similar Content
How to Add Formatting to Cells and Data in Excel Styles, Fonts, Colors, & More
Tutorial: In this tutorial I will cover how to use the various formatting tools in Excel. The Format...
Convert Numbers Stored as Text to Numbers in Excel
Tutorial: I'll show you 4 ways to convert numbers stored as text to numbers in Excel.  This situati...
Simple Alternatives to UserForms
Tutorial: This tutorial covers a few simple ways to show pop-up windows to users that allows you to ...
Excel Forum