• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Basic question on VBA autofilter "Field" code.

Jagdev Singh

Active Member
Hi Experts

I just want to know if the Field code in the VBA autofilter can be changes to name of the column say "Name" instead of the number of the column. I googled it and find that the data type of it is Variant.

Code:
ActiveSheet.ListObjects("Table").Range.AutoFilter Field _
        :=25

Regards,
JD
 
You would try

Code:
Dim c As Long
c = 25
ActiveSheet.ListObjects("Table").Range.AutoFilter Field:=c
 
Here is an example workbook with coding.

Code:
Sub TestFilter()
Dim iCol As Long
iCol = 25
    [A1].CurrentRegion.AutoFilter iCol, 1
End Sub

No errors.

Take care

Smallman
 

Attachments

  • AllSmooth.xlsm
    15.3 KB · Views: 4
Back
Top