Link to home
Start Free TrialLog in
Avatar of joyacv2
joyacv2Flag for Puerto Rico

asked on

FILTER ON EXCEL TABLE IN VBA

Hi,

I need a vba code to create custom filters on excel columns within a table, any idea?
BOOK2.xlsm
Avatar of Steven Harris
Steven Harris
Flag of United States of America image

Can you be a little more specific?  What are you wanting to filter by?  Is it always the same string, column, etc.?
Avatar of joyacv2

ASKER

hi,

For example in the columnA in the included workbook, filters the columnA for fields that contains letter V, but using VBA not table filter options
Are you familiar with VBA at all?  You can modify the below example as needed:

Sub FilterCriteria()
With Sheet1
    .AutoFilterMode = False
    .Range("A1:D1").AutoFilter
    .Range("A1:D1").AutoFilter Field:=1, Criteria1:="*V*"
    End With
End Sub

Open in new window


Line 2 - Needs to be the name of the sheet
Line 4 - Table Header Range
Line 5 - "*V*" searches for the letter V in a string


This works as expected in the example you provided.
BOOK2.xlsm
Avatar of joyacv2

ASKER

Hi,

I am familiar with VBA. How you specify by column name and not by range, this is because in my code the table can start in any cell and can be any number of fields in it?
joyacv2,

Can you please be more specific on how the table will start in any cell? Do you mean by it can start in any column or do you mean it can start randomly in any place on the worksheet?
Avatar of joyacv2

ASKER

hi,

for example, the columnA of the table can be in the cell c3 or any other
ASKER CERTIFIED SOLUTION
Avatar of Steven Harris
Steven Harris
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joyacv2

ASKER

exellent, perfect!!!!