ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Run-Time Error (https://www.excelbanter.com/excel-worksheet-functions/57980-run-time-error.html)

Connie Martin

Run-Time Error
 
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

Dave Peterson

Run-Time Error
 
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.

Connie Martin wrote:

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


--

Dave Peterson

Connie Martin

Run-Time Error
 
Thank you very much. That works very nicely. Connie

"Dave Peterson" wrote:

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.

Connie Martin wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 09:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com