Excel VBA Uppercase: UCase, Macros, and Cell Options

VBA & macros · Updated November 10, 2026

Excel VBA Uppercase: UCase, Macros, and Cell Options

Yes. In Excel VBA, use UCase$ to return a text string in uppercase; to change worksheet cells, assign that result back to the cells. For example, a macro can convert selected text while leaving numbers and formulas untouched. If you only need a worksheet formula, Excel’s UPPER function is often simpler.

What “uppercase” means in Excel VBA

Uppercase conversion changes lowercase letters into their uppercase equivalents. It does not translate text, remove spaces, or turn a number into a different value. For example, converting “north ridge” produces “NORTH RIDGE”; punctuation and digits remain as they were. A string such as “Room 4B” becomes “ROOM 4B”.

VBA’s built-in UCase function returns a copy of the supplied string with lowercase characters converted. Its dollar-sign form, UCase$, returns a String rather than a Variant, so it is a convenient choice when the input is known to be text. Neither function changes a worksheet cell by itself: the code must use the returned value, such as by assigning it to a variable or cell.

That distinction matters when you are searching for a command to “make a column uppercase.” Calling UCase$ on a value in code only creates a converted result. Writing that result back changes the cell, while using the function in a worksheet formula displays a converted result elsewhere.

How UCase$ works in a VBA expression

Use the function wherever VBA expects a string. This small example shows the conversion in memory; it does not write to a worksheet:

Sub ShowUppercaseExample()
    Dim sourceText As String
    Dim upperText As String

    ' Convert the text and store the result in a separate variable.
    sourceText = "North Ridge"
    upperText = UCase$(sourceText)

    MsgBox upperText
End Sub

The message box displays “NORTH RIDGE.” The original variable still contains “North Ridge,” because the result was assigned to a different variable. To replace the original variable instead, assign the result back to it: sourceText = UCase$(sourceText).

VBA also has LCase$ for lowercase conversion. Uppercase conversion is not the same as comparing text without regard to case. For comparisons, VBA offers options such as setting Option Compare Text at the top of a module, or comparing normalized strings. Choose a comparison method deliberately; changing display text just to make a comparison can discard the original capitalization.

Convert selected worksheet cells with a macro

The following macro converts text constants in the current selection. It skips formulas and non-text values, so a date, number, or formula result is not replaced. Before running any macro, save a copy of the workbook: macro changes cannot be undone with Ctrl+Z.

Option Explicit

Sub UppercaseSelectedText()
    Dim selectedRange As Range
    Dim cell As Range

    ' Do nothing if the current selection is not a worksheet range.
    If TypeName(Selection) <> "Range" Then Exit Sub
    Set selectedRange = Selection

    ' Convert text constants only; leave formulas and other values alone.
    For Each cell In selectedRange.Cells
        If Not cell.HasFormula Then
            If VarType(cell.Value2) = vbString Then
                cell.Value2 = UCase$(CStr(cell.Value2))
            End If
        End If
    Next cell
End Sub

To use it in Excel for Microsoft 365 on Windows, save a workbook copy, select the cells to change, open the Visual Basic Editor with Alt+F11, and insert the code into a standard module using Insert > Module. Run the macro from the editor or from Excel’s macro list. Save a workbook that needs to retain VBA as an Excel Macro-Enabled Workbook (.xlsm); a regular .xlsx file does not store VBA code.

On a Mac, desktop Excel also supports VBA. Option+F11 commonly opens the Visual Basic Editor, though some keyboards require Fn as well. The precise key depends on the keyboard and its function-key settings. Excel for the web cannot create, edit, or run VBA macros; open the workbook in the desktop app to use this code.

The macro acts only on the selection, which makes selecting a limited range important. It visits every selected cell, including cells in a multi-area selection. A protected sheet or locked cells may prevent writing and cause an error. Unprotect the sheet only if you are authorized to do so, or work with an editable copy.

Keep the original text with Excel’s UPPER formula

A formula is a useful alternative when you want the uppercase result in a separate column and want to preserve the source. With the text “North Ridge” in cell A2, enter this formula in B2:

With the source text in A2, =UPPER(A2) returns NORTH RIDGE.

Copy or fill the formula down beside the remaining source values. The results update if the source cells change, and the original column remains intact. When you need fixed text rather than formulas, copy the results and use Paste Special > Values to replace formulas with their current results. The formula route is usually easier for a one-time transformation that should remain linked to its source; a macro is useful when you need to overwrite selected cells or repeat the operation with a command.

In VBA, you can also place a formula in a worksheet cell, but that is not necessary for a simple conversion. A formula-filled output range and a macro that writes uppercase values have different consequences: formulas remain dependent on their inputs, whereas values written by the macro no longer update when the original text changes.

Choosing the right method

Pick a method based on whether the source must remain available, how often the task will be repeated, and whether your environment can run macros.

  • Use UPPER in a worksheet formula when you want to keep the original text and see an automatically updated result.
  • Use UCase$ in VBA when other VBA code needs an uppercase string for a comparison, label, file name, or later calculation.
  • Use a macro that writes back to cells when you deliberately want to replace text in a selected range and have a repeatable desktop workflow.
  • Use Flash Fill or a one-off manual transformation if the task is small and you do not want to add a macro. Check the generated values, especially when the text has irregular patterns.

For a shared workbook, a formula or non-macro workflow may be easier for other people to use because macro execution can be restricted by security settings and is unavailable in Excel for the web. A macro is not automatically the best option simply because the task involves many cells; formulas, Power Query, or another supported data-cleaning workflow may fit better when conversion is part of a larger repeatable import process.

Common problems and useful safeguards

A frequent mistake is expecting the function to alter the source automatically. For example, assigning upperText = UCase$(sourceText) changes only upperText. To affect a cell, the code must assign the result to a range, such as someCell.Value = UCase$(CStr(someCell.Value)). That direct assignment is appropriate only after deciding that overwriting the cell is intended.

Another common mistake is running a macro with the wrong selection. A whole-column selection can mean processing more than a million worksheet rows, even if most cells are empty. The example macro checks every selected cell, so select only the populated range where practical. If you need to process a very large dataset, a purpose-built approach that reads values into an array and writes them back in one operation can reduce worksheet interaction, but it requires more careful handling of formulas, blanks, errors, and formatting.

The sample skips formulas to protect them, but it will replace text constants, including text that looks like a number, such as an identifier stored as text. That is intentional: uppercase conversion does not convert a genuine numeric cell. It also does not trim leading or trailing spaces. If spaces need to be removed, treat that as a separate transformation and check the impact before combining it with a macro.

Cell formatting is not the same thing as stored text. A number format can display a value in a particular way, but uppercase conversion is for strings. It also cannot make a formula itself uppercase as a way of changing its result; it can only transform text returned by that formula if you wrap the formula in the worksheet UPPER function, or process the resulting text in VBA.

Language, security, and compatibility

Case conversion can have language-specific details. Basic English letters convert as expected, while accented and other non-English characters can depend on the character and the system’s language rules. If a workbook is used across regions or contains names in multiple languages, test representative values in the actual Excel environment before making a permanent replacement. Uppercasing is not the same as removing accents, and it should not be used to standardize identities or names without considering the data’s language.

Macros can change workbook contents, so run code only when you understand what it will affect. Do not enable macros in an unfamiliar file merely to view its data. Keep a backup, inspect the selected range, and save a macro-enabled copy if you need to retain the code. Organization-managed Excel settings may restrict macros, and a user may need to follow their organization’s approved process rather than changing security settings.

The VBA examples are for desktop Excel on Windows or Mac. Excel for the web can display a workbook containing VBA, but it does not execute the VBA code. A workbook can therefore show prior results in the browser without being able to run the conversion macro there.

Frequently Asked Questions

What is the VBA code for uppercase?

Use UCase$(text), where text is a string or an expression that supplies text. It returns an uppercase string; assign that result to a variable or cell if you want to keep it.

How do I make an entire column uppercase in Excel VBA?

Select only the populated cells in the column and run a macro that loops through the range, converting text values. The example above skips formulas and other value types. Avoid selecting an entire worksheet column unless the code is designed to handle its full size efficiently.

Can I use UCase in an Excel worksheet cell?

UCase$ is a VBA function, not a standard worksheet formula. In a worksheet cell, use Excel’s UPPER function, such as =UPPER(A2) when the source is in A2.

Does UCase change the original string?

No. It returns a converted string. The original value changes only if your code assigns the result back to the original variable or worksheet cell.

Can Excel for the web run an uppercase VBA macro?

No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel for Windows or Mac to run VBA, or use a worksheet formula such as UPPER for a browser-compatible approach.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.