Run-Time Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The following macro gives me a "run-time error '13' Type mismatch" pop-up
when I delete row. When I click on Debug it is the ".Value=UCase(.Value)"
that's highlighted. What is wrong? Connie

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("B18:B100,F18:F100")) Is
Nothing) Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If
End Sub
 
Since you're deleting a row, you're changing the cell in column B and F. Two
cells don't have a simple value you can check.

I think I'd look for multiple cells and quit if I find them:

Private Sub Worksheet_Change(ByVal Target As Range)
if target.cells.count > 1 then exit sub
If Not (Application.Intersect(Target, Range("B18:B100,F18:F100")) 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

The .enableevents stop the change from firing the code again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top