Cells UPPER CASE automatically

Steve_C

New Member
Joined
Aug 27, 2003
Messages
29
Hi guys,

is there any way I can format a cell so that when text is entered into it as CAPS or lower case, they are always automatically converted to UPPER CASE.

I tried the =UPPER function but this does not work as its a circular function when applying it to itself. I know I could use this function to display the desired results in another column, but I would really rather only have the one column if possible.

Sorry if this is a bit basic but I'm struggling with this one.

thanks in advance
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,494
Hi,

You could try a change event:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If UCase$(Target.Text) <> LCase$(Target.Text) Then Target.Value = UCase$(Target.Value)
End Sub

To install, right-click the sheet tab, select 'View Code' & paste above into code window
 

pauleapo

Board Regular
Joined
Nov 23, 2005
Messages
73
Sorry to post inside this topic, but it relates slightly.

How would i do the same for certain columns or a range ie A3 to A299 that i wanted a specified case?



Paul
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,494

ADVERTISEMENT

pauleapo said:
Sorry to post inside this topic, but it relates slightly.

How would i do the same for certain columns that i wanted a specified case?



Paul

Hi Paul,

this code only operates on columns B and C:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 2 Or Target.Column > 3 Then Exit Sub
If UCase$(Target.Text) <> LCase$(Target.Text) Then Target.Value = UCase$(Target.Value)
End Sub
 

EJ42955

Board Regular
Joined
Apr 18, 2006
Messages
101
this code only operates on columns B and C:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 2 Or Target.Column > 3 Then Exit Sub
If UCase$(Target.Text) <> LCase$(Target.Text) Then Target.Value = UCase$(Target.Value)
End Sub

I used this for Worksheet_SelectionChange, also.
Specified a single column, "AE".
And, it works great. 2 lines of code to accomplish this task is awesome.


Thanks, to al_b_cnu.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Column <> 31 Then Exit Sub
If UCase$(Target.Text) <> LCase$(Target.Text) Then Target.Value = UCase$(Target.Value)

End Sub

E J
Edited: 3/30/2007 11:22 AM
Actually, after a little further investigation, this works best...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 31 Then Target.Value = UCase$(Target.Value)

End Sub
Text is changed as soon as you exit the cell.
 

ricochetrob

Board Regular
Joined
Aug 23, 2004
Messages
67

ADVERTISEMENT

That's great!

I'm a novice so this is a novice question....

What if I wanted to apply Proper Case to column AE?
How would I write it to indicate Proper?
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
I don't think there's a function to directly do that within VBA, but you can use the WorksheetFunction Proper to achieve it:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 31 Then Target.Value = Application.WorksheetFunction.Proper(Target.Value)

End Sub
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You'll want to use Application.EnableEvents to keep the macro from repeatedly calling itself, the following will also allow this to work with multiple cells:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range
Set d = Intersect(Target, Columns(31))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
    For Each c In d
        c = Application.WorksheetFunction.Proper(c)
    Next
Application.EnableEvents = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,760
Messages
5,574,080
Members
412,566
Latest member
TexasTony
Top