Auto Capitalize Column

Ottsel

Board Regular
Joined
Jun 4, 2022
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I'm struggling to find a way for my data that's entered to automatically be capitalized, as some other users are not careful when entering data. Currently I've been using the code posted below to do the trick, but it can cause a delay from time to time. The way it works is it updates whenever you change sheets, so that is the cause of the delay. I was hoping to find a better solution.

Any suggestions or tips would be highly appreciated!
VBA Code:
Private Sub Worksheet_Activate()
On Error Resume Next
Application.ScreenUpdating = False

Dim cell As Range

For Each cell In Range("$B$1:" & Range("$c$10000").SpecialCells(xlLastCell).Address)
    cell.Value = UCase(cell.Value)
Next cell

On Error GoTo 0
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Rather than using the Worksheet_Activate event, would it be better to use the Worksheet_Change event, and detect if a change was made in cells B1:C10000, like so:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("B1:C10000")) Is Nothing Then Target.Value = UCase(Target.Value)
Application.EnableEvents = True
End Sub
Whenever someone enters text into B1:C10000, it will automatically convert it to upper case.
 
Upvote 0
Solution
Rather than using the Worksheet_Activate event, would it be better to use the Worksheet_Change event, and detect if a change was made in cells B1:C10000, like so:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("B1:C10000")) Is Nothing Then Target.Value = UCase(Target.Value)
Application.EnableEvents = True
End Sub
Whenever someone enters text into B1:C10000, it will automatically convert it to upper case.
Worked like a charm. The if statement vs a for each loop is much more effective, plus the suggestion of a Worksheet_Change Event compared to an Activate. Thank you!
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,288
Members
448,563
Latest member
MushtaqAli

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