Run Time Error 13 Type Mismatch

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,570
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro below to delete rows from row 2 onwards containing "Reference" in Col A

Code:
 Sub Del_Unwanted()
Dim LR As Long, i As Long
With Sheets("Data Import")
If .Range("A2") = "" Then
.Range("A1").EntireRow.Delete
Else
End If
LR = .Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
'On Error Resume Next

If .Range("A" & i).Value = "Reference" Then .Range("A" & i).EntireRow.Delete
Next i
.UsedRange.EntireColumn.AutoFit
End With
  End Sub


I add code below, then it works
Code:
 'On Error Resume Next before 

If .Range("A" & i).Value = "Reference" Then .Range("A" & i).EntireRow.Delete

Kindly amend my code so I do not need to include on error resume next


Your assistance in this regard is most appreciated
 

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.
So well elaborate why such codeline should be necessary as I can't see within your code any reason …​
 
Upvote 0
Do you have error values in column A?
 
Upvote 0
When I filter there is #Name in the Filter
 
Upvote 0
Then you need to test for errors separately:

Code:
If not Iserror(.range("A" & i).value) then 
   If .Range("A" & i).Value = "Reference" Then .Range("A" & i).EntireRow.Delete
end if
 
Upvote 0

Forum statistics

Threads
1,215,891
Messages
6,127,603
Members
449,388
Latest member
macca_18380

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