VBA Autofilters

dan8825

New Member
Joined
Dec 24, 2018
Messages
26
Hey!

I've seen this thread which seems to be what I'm after, but doesn't quite work for me...

https://www.mrexcel.com/forum/excel-questions/593812-macro-autofilter-skip-if-blank.html

When I use the answer here it skips even if there is a field present. Below is what I have, there are several filters in play it is just the last one which is the issue where it is text specific. This could be one of 8 variants but will not always be there based on the previous filters.

Any help greatly appreciated!




ActiveSheet.Range("$A$1:$V$3000").AutoFilter Field:=13, Criteria1:="Y"
ActiveSheet.Range("$A$1:$V$3000").AutoFilter Field:=15, Criteria1:="<=0", _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$V$3000").AutoFilter Field:=14, Criteria1:=">0", _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$V$3000").AutoFilter Field:=3, Criteria1:=">0", _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$V$3000").AutoFilter Field:=10, Criteria1:="Dubai Air", _
Operator:=xlAnd




Range("B2:C3000").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet1").Select
Application.CutCopyMode = False
Sheets("Sheet1").Copy
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi & welcome to MrExcel.
How about
Code:
   With ActiveSheet.Range("$A$1:$V$3000")
      .AutoFilter Field:=13, Criteria1:="Y"
      .AutoFilter Field:=15, Criteria1:="<=0"
      .AutoFilter Field:=14, Criteria1:=">0"
      .AutoFilter Field:=3, Criteria1:=">0"
      .AutoFilter Field:=10, Criteria1:="Dubai Air"
      If .SpecialCells(xlVisible).Count = 22 Then Exit Sub
   End With
   Range("B2:C3000").Copy
   Sheets("Sheet1").Range("A2").PasteSpecial xlPasteValues
 
Upvote 0
Hi Fluff,

Thanks for the quick response! doesn't seem to have worked, I also want it to go onto the search for a new word instead of "Dubai Air" rather than end the macro. Much like the thread I mentioned seems to do


Thanks!


With ActiveSheet.Range("$A$1:$V$3000")
.AutoFilter Field:=13, Criteria1:="Y"
.AutoFilter Field:=15, Criteria1:="<=0"
.AutoFilter Field:=14, Criteria1:=">0"
.AutoFilter Field:=3, Criteria1:=">0"
.AutoFilter Field:=10, Criteria1:="Dubai Air"

If .SpecialCells(xlVisible).Count = 22 Then Exit Sub
End With


Range("B2:C3000").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet1").Select
Application.CutCopyMode = False
Sheets("Sheet1").Copy
 
Upvote 0
In what way didn't it work?
Also when posting code please use code tags, the # icon in the reply window.
 
Upvote 0
Where Dubai Air is not present in the filter, it selects nothing and the other filter options I do not want present are selected
 
Upvote 0
Full list reads as below.

Where the previous filters rule an option out I would like it to skip to the next one, the macro I have pasted just repeats itself except changing the last text filter to one of the below.

Hope I'm being clear, Thanks!

[TABLE="width: 125"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Chile Air[/TD]
[/TR]
[TR]
[TD]Peru Air[/TD]
[/TR]
[TR]
[TD]Singapore Sea[/TD]
[/TR]
[TR]
[TD]Singapore Air
Dubai Air[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Maybe
Code:
  With ActiveSheet.Range("$A$1:$V$3000")
      .AutoFilter Field:=13, Criteria1:="Y"
      .AutoFilter Field:=15, Criteria1:="<=0"
      .AutoFilter Field:=14, Criteria1:=">0"
      .AutoFilter Field:=3, Criteria1:=">0"
      .AutoFilter Field:=10, Criteria1:="Dubai Air"
      If .SpecialCells(xlVisible).Count > 22 Then
         Range("B2:C3000").Copy
         Sheets("Sheet1").Range("A2").PasteSpecial xlPasteValues
      End If
      .AutoFilter Field:=10, Criteria1:="Chile Air"
      If .SpecialCells(xlVisible).Count > 22 Then
         'do something
      End If
      'etc
      'etc
   End With
 
Upvote 0
I have not used end with before.. so not sure the limitations, Is below what the full code should look like for two opitons?

As I get error invalid or unqualified reference


Code:
Sub Macro1()'
' Macro1 Macro
'


'  With ActiveSheet.Range("$A$1:$V$3000")
      .AutoFilter Field:=13, Criteria1:="Y"
      .AutoFilter Field:=15, Criteria1:="<=0"
      .AutoFilter Field:=14, Criteria1:=">0"
      .AutoFilter Field:=3, Criteria1:=">0"
      .AutoFilter Field:=10, Criteria1:="Dubai Air"
      If .SpecialCells(xlVisible).Count > 22 Then
         Range("B2:C3000").Copy
         Sheets("Sheet1").Range("A2").PasteSpecial xlPasteValues
      End If
      .AutoFilter Field:=10, Criteria1:="Chile Air"
      If .SpecialCells(xlVisible).Count > 22 Then
         'do something
   End With
 
Upvote 0
Oops, it should be
Code:
  With ActiveSheet.Range("$A$1:$V$3000")
      .AutoFilter Field:=13, Criteria1:="Y"
      .AutoFilter Field:=15, Criteria1:="<=0"
      .AutoFilter Field:=14, Criteria1:=">0"
      .AutoFilter Field:=3, Criteria1:=">0"
      .AutoFilter Field:=10, Criteria1:="Dubai Air"
      If .SpecialCells(xlVisible).Count > 22 Then
         [COLOR=#ff0000].Parent.[/COLOR]Range("B2:C3000").Copy
         Sheets("Sheet1").Range("A2").PasteSpecial xlPasteValues
      End If
      .AutoFilter Field:=10, Criteria1:="Chile Air"
      If .SpecialCells(xlVisible).Count > 22 Then
         'do something
      End If
      'etc
      'etc
   End With
As I don't know what you want to do for the other options I can't show how to do it.
 
Upvote 0
Thanks, I think this seems to being doing the job..

I will fill in everything else I need and fingers crossed.

Thanks very much, have a great Christmas!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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