Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Dynamic autofilter field

Hiya,

I want to set an autofilter in my macro, but the autofilter field isn't
necessarily always going to be the same number. It will always have the same
column header though.

Is there a way to change the number to the column header, or make it filter
on the 'active column'?

Selection.AutoFilter Field:=14,

Thanks
merry_fay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Dynamic autofilter field

Maybe you could just remove any existing filter and then filter the single
column by what you want.

Don't select the entire range (multiple columns), just the column that you want
to filter.

The entire row will still be hidden/shown when you filter.

Then it's gonna be something like:

Dim wks As Worksheet
Set wks = ActiveSheet
wks.AutoFilterMode = False
ActiveCell.EntireColumn.AutoFilter field:=1, Criteria1:="asdf"

merry_fay wrote:

Hiya,

I want to set an autofilter in my macro, but the autofilter field isn't
necessarily always going to be the same number. It will always have the same
column header though.

Is there a way to change the number to the column header, or make it filter
on the 'active column'?

Selection.AutoFilter Field:=14,

Thanks
merry_fay


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Dynamic autofilter field

If you want those arrows on all your headers, you could use something like:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim RngToFilter As Range
Dim myField As Long

Set wks = ActiveSheet

With wks
.AutoFilterMode = False
Set RngToFilter = .Range("A1:O" _
& .Cells(.Rows.Count, "A").End(xlUp).Row)
myField = ActiveCell.Column

If myField RngToFilter.Columns.Count Then
MsgBox "Select a cell in the right range!"
Exit Sub
End If
RngToFilter.AutoFilter field:=myField, Criteria1:="asdf"
End With

End Sub

This filters columns A:O based on the used rows in column A.





merry_fay wrote:

Hiya,

I want to set an autofilter in my macro, but the autofilter field isn't
necessarily always going to be the same number. It will always have the same
column header though.

Is there a way to change the number to the column header, or make it filter
on the 'active column'?

Selection.AutoFilter Field:=14,

Thanks
merry_fay


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Autofilter? Sarah (OGI) Excel Discussion (Misc queries) 0 October 8th 07 12:25 PM
Dynamic Field Selection - Calculation Matt Cromer Excel Discussion (Misc queries) 1 August 21st 06 11:13 PM
Dynamic Chart With Autofilter and Formulae Gadget Charts and Charting in Excel 0 October 27th 05 03:02 PM
dynamic summing of an autofilter 'ed table john boy Excel Discussion (Misc queries) 4 May 19th 05 05:29 AM
Dynamic series range from AutoFilter CLR Charts and Charting in Excel 7 April 15th 05 02:53 PM


All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"