VBA to filterout #N/A If not

Revathi Kannan

New Member
Joined
Jan 27, 2012
Messages
23
Hi all,

I have the below macro wherein it will filter the value apart from #N/A and delete the entire row but i need to release the filter if the below doesn't meets the requirement. Please assist:):)

Worksheets("code").Activate
Range("$A$1:$BE$10").AutoFilter Field:=28, Criteria1:="<>#N/A"
With ActiveSheet.AutoFilter.Range
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You should probably add something to your formula that changes an error (#N/A) to something else
=IFERROR(YourFormula,"###")
The reason is #N/A is a little tricky to find unless you create an Array formula

Then add a line in your code to find any ### values

Code:
Dim F as Variant
F = Application.Match("###",Range("A1:BE10"))
if IsError(F) = False then
   Worksheets("code").Activate   Range("$A$1:$BE$10").AutoFilter Field:=28, Criteria1:="<>#N/A"
   With ActiveSheet.AutoFilter.Range
     .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
   End With
end if
 
Upvote 0
Hi Jeffrey,

Thanks for your reply but your code is not working. I have replaced #N/A with blanks. Below is my actual requirement.

>I need to filter the data in column B apart from blanks and delete the entire row.
> If no data found in column B then i need to release the filters and move on to the next subroutine.

Is it possible ?
 
Upvote 0
Hello Revathi Kannan
this will go through all the cells in the range and delete the entire row wherever cell = #N/A and shift rows up :beerchug:
Code:
Sub a()
Dim r As Range, rr As Range
With Worksheets("code")
Set r = Range("$A$1:$BE$10")
For Each rr In r
If WorksheetFunction.IsNA(rr) Then Rows(rr.Row).EntireRow.Delete shift:=xlUp
Next
End With
End Sub
 
Upvote 0
Hi r1998,

Thanks for your reply but my request is to run 2 conditions.

Condition 1 - I need to filter the data in column B apart from blanks and delete the entire row.
Condition 2 -
If no data found in column B then i need to release the filters and move on to the next subroutine.
 
Upvote 0
have not tested this
Code:
Sub a()
Dim r As Range, rr As Range
With Worksheets("code")
Set r = Range("$A$1:$BE$10")
If WorksheetFunction.CountA(r) = 0 Then
Call subroutine
Exit Sub
End If
For Each rr In r
If WorksheetFunction.IsNA(rr) Then Rows(rr.Row).EntireRow.Delete shift:=xlUp
Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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