VBA Convert to uppercase in the on change function

rplohocky

Active Member
Joined
Sep 25, 2005
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hello,
I'm looking for code to insert into the "on change" area that will convert lower case into upper case. The code would need to be for just column H. It should convert as soon as you leave the cell or another words after update. Thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Can you clarify the upper case.

Do you mean the entire contents should be upper case or just the first letter of a word?

hello there
should be
HELLO THERE
or
Hello There
?
 
Upvote 0
Something like this should do ...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 8 Then
    Application.EnableEvents = False
    Target = UCase(Target.Text)
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
If you want proper case like Jonmo1 suggested, the line should be Target = Application.WorksheetFunction.Proper(Target.Text)
 
Upvote 0
Here's another code, so it can handle multiple cells changing at once. And other errors

This capitalizes the whole cell.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range, c As Range
Set MyRange = Intersect(Target, Range("H:H"))
If Not MyRange Is Nothing Then
    Application.EnableEvents = False
    On Error GoTo handlr
    For Each c In MyRange
        c.Value = UCase(c.Value)
    Next c
End If
handlr:
Application.EnableEvents = True
End Sub


As Codeninja said, change Ucase to Application.Proper if you want it the other way.
 
Upvote 0
Something like this should do ...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 8 Then
    Application.EnableEvents = False
    Target = UCase(Target.Text)
    Application.EnableEvents = True
End If
End Sub

Thank you CodeNinja! That was what I was looking for. And thank you to everyone else for responding!
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,360
Members
448,888
Latest member
Arle8907

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