Force converting to UPPER CASE problems

Sven62

Active Member
Joined
Feb 21, 2012
Messages
485
I found the following code to automatically change lower case in specified cells to upper case. It does work, however if I clear more than one cell at a time I get an error "Run-time error '13': Type mismatch."

In addition to the error message, after debugging, the code doesn't work anymore until I enable events TRUE in the Immediate Window, or close and reopen the workbook.

Any ideas?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)    
If Not (Application.Intersect(Target, Range("A2:A150")) _
      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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
What if you use this Change event procedure instead (one benefit is that you can copy/paste multiple cells into Column A and they all will be processed)...
Code:
Private Sub Worksheet_Change(ByVal target As Range)
  If Not Intersect(target, Range("A2:A150")) Is Nothing Then
    Application.EnableEvents = False
    Range("A2:A150") = [IF(A2:A150="","",UPPER(A2:A150))]
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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