Macro to delete rows containing #N/A

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have written code to delete all rows to clear data containing #N/A (Columns A to F)

It comes up with a run time error 13 Type Mismatch and the following code is highlighted

If IsError(Cells(i, "A") + 1) Then .Rows(i).Delete

It would be appreciated if you could assist


Sub Delete_NA()
Dim i As Long
Dim LastRow As Long

With Application

.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 4 Step -1

If IsError(Cells(i, "A") + 1) Then .Rows(i).Delete



Next i
End With

With Application

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
howard,


Rich (BB code):
'Change this:
'If IsError(Cells(i, "A") + 1) Then .Rows(i).Delete

'To this:
If IsError(.Cells(i, "A")) Then .Rows(i).Delete
 
Upvote 0
Hi Peter

Thanks for the help, much appreciated
 
Upvote 0
I have wriiten dcode to delete all rows where the word "showroom" appears in col A, but nothing happens when activating the macro

Sub Del_Showroom()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 6 Step -1
If Range("A" & i).Value Like "*Showroom*" Then Rows(i).Delete
Next i
End Sub

Your assistance will be most appreciated
 
Upvote 0
Try:

Code:
Sub Del_Showroom()
Dim LR As Long, i As Long
LR = Range("A" & rows.Count).End(xlUp).row
Application.ScreenUpdating = False
For i = LR To 6 Step -1
    If InStr(LCase$(Range("A" & i).Value), "showroom") > 0 Then rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

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