Upper case

B

Beginner2005

hi
new to excel building so please bare with me. is there any way to format a
worksheet so that any data entered is automatically converted to upper case?
 
B

Bob Phillips

Not by formatting, but you can add event code behind it

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
Target.Value = UCase(Target.Value)

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
HTH

Bob Phillips

Beginner2005 said:
hi
new to excel building so please bare with me. is there any way to format a
worksheet so that any data entered is automatically converted to upper
case?
 
B

Beginner2005

Bob Phillips said:
Not by formatting, but you can add event code behind it

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
Target.Value = UCase(Target.Value)

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
HTH

Bob Phillips


case?
 
B

Beginner2005

Hi Bob
thanks for the help, quick question, is there any way to modify this code to
exclude a specific column i.e column 'C'?
 
B

Bob Phillips

Yeah, not hard.

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Column <> 3 Then
.Value = UCase(.Value)
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub
 
B

Bob Phillips

A slight variation, so that formulas don't get wiped

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Column <> 3 Then
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub
 
Top