To change an Excel VBA UserForm label’s text color, set its ForeColor property. For example, in the UserForm’s code module, use Me.lblStatus.ForeColor = RGB(0, 102, 204) to make a label named lblStatus blue; you can also set ForeColor in the Properties window without writing code.
Which property controls label text color?
A Label control’s ForeColor property determines the color of its displayed text. The property accepts a color value, commonly supplied with VBA’s RGB function. RGB takes red, green, and blue components in that order, each from 0 to 255. For example, RGB(255, 0, 0) is red, RGB(0, 0, 0) is black, and RGB(255, 255, 255) is white.
This is different from a worksheet cell’s Font.Color property. A UserForm label is a Microsoft Forms control, so use LabelName.ForeColor, not LabelName.Font.Color. The label’s Font property controls characteristics such as the typeface, size, and bold or italic styling; use ForeColor for the text color. The label’s Caption property, meanwhile, contains the text itself.
Set the color in the Properties window
For a color that will remain the same every time the form opens, setting it at design time is straightforward. In Excel for Microsoft 365 on Windows, open the Visual Basic Editor with Alt+F11, find the workbook’s project in Project Explorer, and open the relevant UserForm. Select the label, then press F4 to display the Properties window if it is hidden. Locate ForeColor and choose a color from the available palette or color dialog.
Check the selected control before changing the setting: the Properties window edits whichever object is selected. If the form itself is selected, you will see the form’s properties rather than the label’s. The label’s (Name) property identifies it in code, while Caption identifies the text it displays. For example, a label might have the name lblStatus and the caption Ready.
Design-time formatting is useful when a label is decorative or has one fixed role, such as a heading or instruction. It also makes the form’s intended appearance visible while you edit it. If code changes the color later, however, the run-time setting can override the appearance you chose in the Properties window.
Set the color with VBA when the form opens
Use the UserForm’s Initialize event to apply a color when the form is created. The example assumes the form contains a label whose (Name) is lblStatus. Add the procedure to that UserForm’s code module, not to a worksheet module or a standard module.
Before running a macro, save a copy of the workbook: VBA changes cannot be undone with Ctrl+Z. Save a macro-enabled workbook as .xlsm if it needs to retain its VBA project.
Private Sub UserForm_Initialize()
Dim labelColor As Long
' RGB components are red, green, and blue, from 0 to 255.
labelColor = RGB(0, 102, 204)
Me.lblStatus.ForeColor = labelColor
End Sub
Me refers to the current UserForm, which makes the target control clear and avoids relying on a form’s default instance. The declared variable stores the color value; assigning the RGB result directly is also valid if a separate variable is not useful. To use a different shade, change the three RGB components. The procedure runs when the form is initialized, so it is a good place to establish the initial appearance before the user interacts with the form.
Choose RGB values and keep text readable
RGB is often more useful than relying on a named color because it lets you specify an exact combination. A color is represented by the intensity of its red, green, and blue components. All-zero components produce black, and all three at 255 produce white. Increasing one component changes that part of the mix; for example, RGB(0, 128, 0) gives a medium green.
When selecting a color, consider the label’s background and the form’s purpose, not just whether the color looks attractive in the editor. Low contrast can make instructions or status messages difficult to read. A pale foreground on a pale background, or a dark foreground on a dark background, is especially easy to miss. Reserve color changes for information they communicate, and do not use color alone to convey an error or success state; include words such as Error or Complete as well.
- Use a dark text color on a light background, or a light text color on a dark background.
- Keep ordinary labels visually consistent; use stronger color differences for meaningful states.
- Check the form at its normal display size, since small labels can make thin or pale text harder to read.
- Consider users who may not distinguish particular colors, and pair the color with clear wording or another visual cue.
The label’s BackColor property controls its background, where that background is visible. Changing BackColor does not change the text, and changing ForeColor does not fill the label’s background. If the background seems absent, inspect the label’s BackStyle property; a transparent setting can allow the form behind it to show through. Choose foreground and background colors as a pair so the text remains legible.
Change color in response to user input
A label can also provide feedback as the user works. For example, a form might show a red prompt while a required text box is empty and a green prompt once the user enters a value. Put the following event procedure in the same UserForm module. It assumes the controls are named txtName and lblPrompt.
As with any VBA, save a copy before running the workbook’s macro-enabled code because macro actions cannot be reversed with Ctrl+Z.
Private Sub txtName_Change()
Dim isBlank As Boolean
' Trim spaces so whitespace alone counts as empty.
isBlank = (Len(Trim$(Me.txtName.Value)) = 0)
If isBlank Then
Me.lblPrompt.Caption = "Enter a name"
Me.lblPrompt.ForeColor = RGB(192, 0, 0)
Else
Me.lblPrompt.Caption = "Name entered"
Me.lblPrompt.ForeColor = RGB(0, 128, 0)
End If
End Sub
The TextBox’s Change event runs when its contents change, so the label updates as the user types. In the Visual Basic Editor, you can select the text box and its Change event from the code window’s procedure lists to create the event procedure for the correctly named control. The test trims leading and trailing spaces before checking the length, so a field containing only spaces is treated as empty. For a form that validates only after a button click, put the check in the button’s Click event instead; that avoids changing the message on every keystroke.
Common problems and fixes
- The code reports that the method or data member was not found: Check the label’s
(Name)property and spelling. The control’s displayed caption is not its code name. A label calledLabel1will not respond to a reference tolblStatus. - The color changes in the editor but not when the form runs: Look for another procedure that assigns
ForeColorafter initialization, such as a button event or a repeated form setup routine. The last assignment that runs determines the visible color. - The code is in the wrong module: A UserForm control is addressed through that form. Put an event procedure in the form’s own code module, or explicitly reference the intended form instance when calling it from elsewhere.
- The chosen color looks different than expected: Confirm the RGB order is red, green, blue, and that each component is between 0 and 255. Also inspect the label’s background and transparency settings.
- The macro does not run: Confirm the workbook is saved in a format that retains VBA and that macros are permitted under the organization’s security settings. Do not enable macros in a file unless its source is trusted.
A further common misconception is that the label’s Caption controls its color. Caption changes only the displayed text. Set ForeColor separately, even if you change Caption and color together in the same event procedure.
Excel versions, Mac, and the web
The examples target desktop Excel for Microsoft 365 on Windows. UserForms and VBA are desktop features; Excel for the web does not run VBA macros or display VBA UserForms as an interactive form. A workbook opened in a browser may retain its VBA project, but the macro-driven form must be used in a desktop version of Excel.
Excel for Mac includes VBA support, but the Visual Basic Editor and some UserForm details can differ from Windows. The Windows shortcut to open the editor is Alt+F11; on many Mac keyboards, use Option+F11, sometimes with Fn depending on the keyboard’s function-key settings. If a shortcut does not work, open the Visual Basic Editor through Excel’s menu or Developer tools. The VBA property assignment using ForeColor and RGB is the same in principle, although a particular control or form feature may behave differently across platforms.
Frequently Asked Questions
How do I change a UserForm label’s font color in Excel VBA?
Assign a color to the label’s ForeColor property, such as Me.lblStatus.ForeColor = RGB(0, 102, 204). Replace lblStatus with the label’s actual (Name).
Can I change label font color without VBA code?
Yes. Open the UserForm in the Visual Basic Editor, select the label, and choose a value for ForeColor in the Properties window. Use VBA when the color needs to change during form use or be set programmatically.
Why does LabelName.Font.Color not work?
A Microsoft Forms label uses ForeColor for its text color. Its Font property handles font formatting such as size and style, while Caption holds the text.
How do I change the label’s background color?
Set BackColor, not ForeColor. If the background is not visible, check whether the label’s BackStyle is transparent.
Can a label change color when a user types?
Yes. Set ForeColor in a TextBox event such as Change, or in a button’s Click event if validation should happen only after the user submits the form.
Related
- Excel Solver: Find Values That Add Up to a Target Sum
- Excel Solver: GRG Nonlinear vs. Simplex LP
- Excel Solver in Google Sheets: Tools, Setup, and Limits
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Range Set: How to Set and Use Excel Cell RangesIn Excel VBA, use the Set keyword to assign a cell or range reference to an object variable:…
- Excel VBA Copy and Paste a Column: Examples and TipsTo copy a column with Excel VBA, use sourceWs.Columns("B").Copy Destination:=targetWs.Columns("D"), replacing the worksheet variables and column letters with…
- VBA Copy and Paste Special: Examples and OptionsIn Excel VBA, copy a range and paste only selected content with Range.Copy followed by Range.PasteSpecial. For example,…
- Excel VBA Find Exact Match: Find Whole-Cell ValuesIn Excel VBA, set the LookAt argument of Range.Find to xlWhole to match an entire cell rather than…
- Excel VBA UserForm: Bring It to the FrontTo bring a modeless Excel VBA UserForm forward on Windows, show it with vbModeless, then use the Windows…
- Microsoft Excel VBA Range: Working With Cells and RangesIn Excel VBA, a Range is an object that represents one cell, a rectangular block of cells, or—in…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.