VBA - Delete row #N/A Issue

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
853
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want to delete all row where Cell contain Word
Rich (BB code):
Remove.

Macro is throwing error at
Rich (BB code):
#N/A
. these rows unable to delete.
if I replace these words with N/A and run a Loop it works. after autofilter also it works.

How to skip #N/A Line and delete other Row.

I want to delete it via loop only. How to achieve this task. Thank.

VBA Code:
Sub Delete_Loop()
Dim i As Long

For i = Range("a" & Rows.Count).End(xlUp).Row To 2 Step -1
       
        If InStr(1, Cells(i, 1).Value, "Remove", vbTextCompare) > 0 Then  '[B] getting error for [B] #N/A , as[/B] type mismatch .[/B]
           
            Cells(i, 1).EntireRow.Delete
           
        End If
   
Next i


End Sub

Below is table.

Book1
A
1Data
2#N/A
3#N/A
4Remove
5Remove
6Finished
7Finished
8#N/A
9Finished
10Finished
11#N/A
12Finished
13Remove
14Finished
15Finished
16#N/A
17Finished
18Finished
Sheet1


Thanks
mg
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,301
Office Version
  1. 365
Platform
  1. Windows
Change the .Value to .Text
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,367
Office Version
  1. 365
Platform
  1. Windows
Also, if that is what your data is really like, no need to use Instr.
Further Rows(i) is simpler than Cells(i,1).EntireRow

If you want to use the looping method to delete the rows ..

VBA Code:
Sub Delete_Loop()
  Dim i As Long
  
  For i = Range("a" & Rows.Count).End(xlUp).Row To 2 Step -1
      If LCase(Cells(i, 1).Text) = "remove" Then Rows(i).Delete
  Next i
End Sub
 

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
853
Office Version
  1. 2010
Platform
  1. Windows
Hi Peter and Fluff,

Thank you for your help, it worked. (y) 🕺


Thanks
mg
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,301
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,098
Messages
5,622,682
Members
415,920
Latest member
ExcelNoob28

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
Top