Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Forcing Input to Uppercase.

Forcing Input to Uppercase

Written by Allen Wyatt (last updated October 6, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


4

If you are developing a worksheet for others to use, you may want them to always enter information in uppercase. Excel provides a worksheet function that allows you to convert information to uppercase, but it doesn't apply as people are actually entering information. For instance, if someone enters information in cell B6, then the worksheet function can't be used for converting the information in B6 to uppercase.

Instead, you must use a macro to do your changing for you. When programming in VBA, you can force Excel to run a particular macro whenever anything is changed in a worksheet cell. The following macro can be used to convert all worksheet input to uppercase:

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
    If Not .HasFormula Then
        .Value = UCase(.Value)
    End If
End With
End Sub

For the macro to work, however, it must be entered in a specific place. Follow these steps to place the macro:

  1. Display the VBA Editor by pressing Alt+F11.
  2. In the Project window, at the left side of the Editor, double-click on the name of the worksheet you are using. (You may need to first open the VBAProject folder, and then open the Microsoft Excel Objects folder under it.)
  3. In the code window for the worksheet, paste the above macro.
  4. Close the VBA Editor.

Now anything (except formulas) that are entered into any cell of the worksheet will be automatically converted to uppercase. If you don't want everything converted, but only cells in a particular area of the worksheet, you can modify the macro slightly:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("A1:B10")) Is Nothing) Then
    With Target
        If Not .HasFormula Then
            .Value = UCase(.Value)
        End If
    End With
End If
End Sub

In this particular example, only text entered in cells A1:B10 will be converted; everything else will be left as entered. If you need to have a different range converted, specify that range in the second line of the macro.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2568) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Forcing Input to Uppercase.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Quickly Entering Dates and Times

Excel provides keyboard shortcuts for a variety of purposes. This tip examines two such shortcuts, designed to allow ...

Discover More

Noting a False Zero On a Chart

When creating charts that will be used by other people, you may need to take some liberties with the presentation of your ...

Discover More

Default Envelope Margins

When you create envelopes in Word, you may want to adjust where the return address and main address are printed. Doing so ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (menu)

Deleting Everything Up to a Character Sequence

Sometimes you have too much information in a cell and you need to "pare down" what is there to get to the info you really ...

Discover More

Shortcut for Selecting a Data Range

Want to select all the data in a contiguous section of a worksheet? The shortcut discussed in this tip makes it very easy.

Discover More

Limiting Number of Characters in a Cell

Need to limit the number of characters that can be entered into a cell? One easy way to do it is through the use of Data ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 0?

2016-11-08 12:42:48

Willy Vanhaelen

@Val

This version of the macro should do what you want:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.HasFormula Then Exit Sub
Application.EnableEvents = False
Target = Evaluate(Replace("IF(ROW(*),UPPER(*))", "*", Target.Address))
Application.EnableEvents = True
End Sub

It is not the macro code who disables the UNDO stack but it is "hard-coded" in EXCEL who clears the undo stack whenever any macro is run.


2016-11-07 20:35:10

VAL

Hi Willy,
I wanted to let you know about a bug with your code: when you a copy/paste of multiple cells the values of all the cells pasted are set equal to the first cell in the copied range. Also the code disables the UNDO command for the edited cells.

Val.


2016-02-07 12:53:40

Willy Vanhaelen

The macros in this tip have a bug and are even dangerous to use !!!

When you enter text the macro is fired, changes the text to upper case and re-enters it in the worksheet which fires the macro... Need I say more?

So to avoid this

.Value = UCase(.Value)

must be replaced by (see the 2007 version)

Application.EnableEvents = False
.Value = UCase(.Value)
Application.EnableEvents = True

Now the bug:

The macros of this tip crash when you select more than one cell, enter text and press Ctrl+Enter.

This version of the first macro deals with it:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.HasFormula Then Exit Sub
Application.EnableEvents = False
Target = UCase(Target.Cells(1))
Application.EnableEvents = True
End Sub

When you enter data in a multiple cell selection and press Ctrl+Enter, Excel enters the data in all cells of the selection and then fires Worksheet_Change. Target does not refer to the active cell but to the entire selection range. So Target.Value = UCase(Target.Value) crashes because UCase can only change text in a single cell. Target = UCase(Target.Cells(1)) in my macro works because Target.Cells(1) is a single cell and Excel fills the entire Target range with its result.

BTW: there is a quicker way to go to the code window of the worksheet: simply right click the sheet's tab and select View Code.


2016-02-06 21:46:04

Dan Fynn

Very useful but for those familiar with how to write micros. Pls how do we get the micros for beginners?


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.