Can I apply Autofilter by Column Title instead of Field #?
The autofilter is already applied to the correct range?
If yes:
Option Explicit
Sub testme01()
Dim myCell As Range
Dim res As Variant
Dim myTitle As String
Dim myCrit As String
myTitle = "Car Model"
myCrit = "gmt001(2)"
With Worksheets("sheet1").AutoFilter.Range
res = Application.Match(myTitle, .Rows(1), 0)
If IsError(res) Then
'no cell with that value
'do nothing
Else
.AutoFilter field:=res, Criteria1:=myCrit
End If
End With
End Sub
MikeZz wrote:
I have the following code that works:
Selection.AutoFilter Field:=3, Criteria1:="GMT001(2)"
I want to be able to do something like:
Selection.AutoFilter Field:="Car Model", Criteria1:="GMT001(2)"
Eventually the "Car Model" would be assigned a variable of Text Type.
Any suggestions on how I could do this?
If there's no silver bullet, is there a property or something that I could
latch on to that has the list of Index'd Column Titles or at least the far
left cell address to offset from?
Thanks,
MikeZz
--
Dave Peterson
|