ENSURE UPPERCASE STATUS AFTER ENTERING DATA

CAROM16

New Member
Joined
Aug 31, 2021
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
Want all input data to be in uppercase for 3 columns - named ranges are: COMMENTS, MARK, and GRADE. Have the following VBA macro which tests for input in these cells and changes lowercase (if any) to uppercase after exiting cell. Macro works great for 1 range, however, when I code all 3 ranges in the macro, than the code doesn't change to uppercase for any of the 3 ranges. I'm assuming I'm doing something wrong with the code but I can't seem to figure it out. Would greatly appreciate any help with respect to this issue. Thank you and regards.

THIS MACRO WORKS PERFECTLY FOR ALL CELLS IN THE "COMMENTS" RANGE.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("COMMENTS")) Is Nothing) Then
With Target
If Not .HasFormula Then
Application.EnableEvents = False
.Value = UCase(.Value)
Application.EnableEvents = True
End If
End With
End If
End Sub

HOWEVER, MACRO DOESN'T WORK FOR ANY OF THE RANGES AFTER ADDING THE "MARK" AND "GRADE" RANGES.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("COMMENTS"), Range("MARK"), Range("GRADE")) Is Nothing) Then
With Target
If Not .HasFormula Then
Application.EnableEvents = False
.Value = UCase(.Value)
Application.EnableEvents = True
End If
End With
End If
End Sub

Once again. thank you for your time and consideration in this matter.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try using Union:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Union(Range("COMMENTS"), Range("MARK"), Range("GRADE"))) Is Nothing) Then
    With Target
    If Not .HasFormula Then
        Application.EnableEvents = False
        .Value = UCase(.Value)
        Application.EnableEvents = True
    End If
    End With
End If
End Sub
 
Upvote 0
Solution
Try using Union:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Union(Range("COMMENTS"), Range("MARK"), Range("GRADE"))) Is Nothing) Then
    With Target
    If Not .HasFormula Then
        Application.EnableEvents = False
        .Value = UCase(.Value)
        Application.EnableEvents = True
    End If
    End With
End If
End Sub
WORKS LIKE A CHARM!!! THANK YOU, THANK YOU, THANK YOY!!!!!!!!!!!!!!!!!!!!
 
Upvote 0
You're welcome.
To make sure it won't be executed when multiple cells changes at the same time (it could happen when you copy-paste multiple cells), add the blue line:
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.CountLarge > 1 Then Exit Sub
If Not (Application.Intersect(Target, Union(Range("COMMENTS"), Range("MARK"), Range("GRADE"))) Is Nothing) Then
    With Target
    If Not .HasFormula Then
        Application.EnableEvents = False
        .Value = UCase(.Value)
        Application.EnableEvents = True
    End If
    End With
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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