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

Printing Only Selected Pages

I often need to print only select pages of a document, rather than the whole thing. Word makes it easy to be judicious in ...

Discover More

Adding an Equation Editor Tool

If you use the Equation Editor a lot in creating your documents, you'll benefit by making sure it is accessible as ...

Discover More

Hiding Gridlines

For those times when you remove the borders from your tables, Word provides a way that you can display non-printing ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Controlling Where You Edit Cell Contents

You can edit cell information either in the Formula bar or in the cell itself. Here's how you can configure Excel to ...

Discover More

Entering Numbers in Excel

Enter information into a cell, and Excel needs to figure out what type of information it is. Here's how Excel interprets ...

Discover More

Combining Multiple Rows in a Column

Do you need to concatenate the contents of a range of cells in the same column? Here's a formula and a handy macro to ...

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 two more than 7?

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.