Uppercase To Cell

data808

Active Member
Joined
Dec 3, 2010
Messages
358
Office Version
  1. 2019
Platform
  1. Windows
I am using this code for column C. I would like to also apply it to column H. Does anyone know how to do that?

VBA Code:
'auto capitalization for all letters in the cell
If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Value = UCase(Target.Value)
Application.EnableEvents = True

I tried a bunch of changes to the code but could not get it to work. Thank you.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range, e As Range
Set d = Intersect(Range("C:C"), Target)
Set e = Intersect(Range("H:H"), Target)
If Not d Is Nothing Then
    Application.EnableEvents = False
        For Each c In d
            c = UCase(c)
        Next
    Application.EnableEvents = True
End If

If Not e Is Nothing Then
    Application.EnableEvents = False
        For Each c In e
            c = UCase(c)
        Next
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Solution
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range, e As Range
Set d = Intersect(Range("C:C"), Target)
Set e = Intersect(Range("H:H"), Target)
If Not d Is Nothing Then
    Application.EnableEvents = False
        For Each c In d
            c = UCase(c)
        Next
    Application.EnableEvents = True
End If

If Not e Is Nothing Then
    Application.EnableEvents = False
        For Each c In e
            c = UCase(c)
        Next
    Application.EnableEvents = True
End If
End Sub

Working great. Thank you very much!
 
Upvote 0
If you want, you could combine into a single range/loop

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
 
  Set Changed = Intersect(Target, Union(Columns("C"), Columns("H")))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
      For Each c In Changed
        c.Value = UCase(c.Value)
      Next c
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range, e As Range
Set d = Intersect(Range("C:C"), Target)
Set e = Intersect(Range("H:H"), Target)
If Not d Is Nothing Then
    Application.EnableEvents = False
        For Each c In d
            c = UCase(c)
        Next
    Application.EnableEvents = True
End If

If Not e Is Nothing Then
    Application.EnableEvents = False
        For Each c In e
            c = UCase(c)
        Next
    Application.EnableEvents = True
End If
End Sub

If you want, you could combine into a single range/loop

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
 
  Set Changed = Intersect(Target, Union(Columns("C"), Columns("H")))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
      For Each c In Changed
        c.Value = UCase(c.Value)
      Next c
    Application.EnableEvents = True
  End If
End Sub
Thanks for the suggestion. I will try it out.
 
Upvote 0

Forum statistics

Threads
1,224,798
Messages
6,181,038
Members
453,014
Latest member
Chris258

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