PC Review


Reply
Thread Tools Rate Thread

Can I apply Autofilter by Column Title instead of Field #?

 
 
=?Utf-8?B?TWlrZVp6?=
Guest
Posts: n/a
 
      1st Jun 2007
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

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      1st Jun 2007
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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reports to link column title to field value james Microsoft Access 6 28th Jan 2009 12:34 AM
Named range=Column title,comumn title in cellB6 use B6in equation =?Utf-8?B?R3JhaGFt?= Microsoft Excel Misc 2 21st Jul 2006 10:03 AM
apply autofilter to more than one table Liviu P via OfficeKB.com Microsoft Excel Worksheet Functions 1 14th Jul 2005 04:13 PM
Possible to apply Autofilter to a subset of available columns? Paul Moore Microsoft Excel Misc 2 1st Jun 2005 10:23 PM
VBA AutoFilter how to apply 2 ranges for selection to copy =?Utf-8?B?RGVubmlz?= Microsoft Excel Misc 1 10th Nov 2004 11:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:27 PM.