If Then Filter Macro

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Here is a filter macro that I use on a daily basis..
How do I modify this for a range that changes daily.
and How do I add an if statement like:
If Results = 0,
Then clear filters and run Firmsignoff Macro (Application.Run "personal. Xlsb! FirmSignoff), save and close WB
Else do nothing

Sub Filter046()
'
' Filter046 Macro
'
' Keyboard Shortcut: Ctrl+d
'
Range("M6").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$N$40").AutoFilter Field:=13, Criteria1:="046"
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What do you mean by
Well like the other macros you replied to, My filter range isn't the same everyday because the route count changes on a daily basis.
In this example, my range isn't stuck to .Range("$A$1:$N$40").
My range is from A:N & row count.
 
Upvote 0
In that case, as long as you don't have any completely blank rows in the date, just use
VBA Code:
ActiveSheet.Range("A1:N1").AutoFilter Field:=13, Criteria1:="046"
 
Upvote 0
In that case, as long as you don't have any completely blank rows in the date, just use
VBA Code:
ActiveSheet.Range("A1:N1").AutoFilter Field:=13, Criteria1:="046"
What about the If and Then statement based off the result. That's the most important part i need help on.
 
Upvote 0
Forgot that part, how about
VBA Code:
With ActiveSheet
   .Range("A1:N1").AutoFilter Field:=13, Criteria1:="046"
   If .AutoFilter.Range.Columns(1).SpecialCells(xlVisible).Count = 1 Then
      Application.Run "personal.Xlsb!FirmSignoff"
   End If
End With
 
Upvote 0
Solution
Forgot that part, how about
VBA Code:
With ActiveSheet
   .Range("A1:N1").AutoFilter Field:=13, Criteria1:="046"
   If .AutoFilter.Range.Columns(1).SpecialCells(xlVisible).Count = 1 Then
      Application.Run "personal.Xlsb!FirmSignoff"
   End If
End With
This was close, but this is what did it. Thanks

Sub Filter046()
'
With ActiveSheet
.Range("A1:N1").AutoFilter Field:=13, Criteria1:="046"
If .AutoFilter.Range.Columns(1).SpecialCells(xlVisible).Count = 1 Then
.AutoFilterMode = False
Application.Run "PERSONAL.XLSB!FirmSignoff"
End If
End With


End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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