VBA to Advance Filter

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
Can you use VBA to run an Advance Filter function?

I want to filter to to value in D8 and I want to filter my table "Vendor_List[Vendor]"

But I want to include "*" before and after the value the D8

Range("Vendor_List[Vendor]").AdvancedFilter Action:=xlFilterInPlace, Unique _
:=False

(I dont want to copy the results, I only want to filter my table)

Can this be done?

Thanks for the help!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Does this do what you want?
I have assumed Z1:Z2 can be used as helper cells.

VBA Code:
Sub AdvFltrTbl()
  Dim rCrit As Range
  
  Set rCrit = Range("Z1:Z2")
  rCrit.Cells(2).Formula = "=ISNUMBER(Search(""" & Range("D8").Value & """," & Range("Vendor_List[Vendor]").Cells(1).Address(0, 0) & "))"
  Range("Vendor_List[#All]").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
  rCrit.ClearContents
End Sub
 
Upvote 0
I want to filter to to value in D8 and I want to filter my table "Vendor_List[Vendor]"

But I want to include "*" before and after the value the D8
.. but I'm wondering why Advanced Filter? Why not AutoFilter?

VBA Code:
Sub AutoFltrTbl()
  With ActiveSheet.ListObjects("Vendor_List")
    .Range.AutoFilter Field:=.ListColumns("Vendor").Index, Criteria1:="*" & Range("D8").Value & "*"
  End With
End Sub
 
Upvote 0
Solution
@Peter_SSs I was about to suggest Autofilter but was busy googling your advanced filter formula method. There is another thread out there at the moment for which that would work really well.
Thanks for posting that.
PS: A good reference for the formula method is Paul Kelly's article here: VBA Advanced Filter: A Complete Guide - Excel Macro Mastery
Sub Heading "Using Formulas as Criteria"
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

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