VBA - Delete row #N/A Issue

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Change the .Value to .Text
 
Upvote 0
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
 
Upvote 0
Hi Peter and Fluff,

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


Thanks
mg
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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