Always upper case

SimonHughes

Active Member
Joined
Sep 16, 2009
Messages
452
Office Version
  1. 365
Platform
  1. Windows
Hello, is it possible to format cells so the result is always upper case even if entered as lower case?

I am using MS365, TIA.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Sure. But it requires VBA.

If you are open to VBA, just let us know what range you want to apply it to, and we can give you the code for that.
 
Upvote 0
This code should do the whole sheet even if the data is pasted in bulk from somewhere else
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
For Each cell In Target
    cell.Value = UCase(cell.Value)
Next cell
End Sub
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor that opens (the code MUST be placed in this Sheet module in order to work automatically).

This will make everything in columns A-C upper case, though the range can be changed to work for any range you want.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
    Set rng = Intersect(Target, Range("A:C"))
    
    If rng Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    
    For Each cell In rng
        cell.Value = UCase(cell.Value)
    Next cell
    
    Application.EnableEvents = True
        
End Sub
 
Upvote 0
Solution
Try putting a break point in the code & when it stops use F8 to step through the code.
 
Upvote 0
Please let me know how so I can learn as I have tested it but must be something I'm not seeing
You need to be very careful with Worksheet_Change event procedures. They fire when a cell is being updated. But if your code is updating a cell, the code will call itself. Hence, you can get caught in an infinite loop.

The way to avoid that is to temporarily disable events from firing while your code is making changes. like I did. You can do that by adding this line prior to making the changes:
VBA Code:
    Application.EnableEvents = False
Then, after all changes are complete, you need to turn it back on again, or else this automated code will stop working in your Excel session.
VBA Code:
    Application.EnableEvents = True
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,095
Members
449,095
Latest member
gwguy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top