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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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