View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Filter Macro that can work for any column/active cell

24 represents the 24th column/field in the range to be filtered.

If you're filtering A1:Z99, then field 24 would be column X.

If you're filtering X1:BC999, then field 24 would be AU.

This may work for you:

Option Explicit
Sub testme()
Dim myRng As Range

Set myRng = ActiveCell.CurrentRegion

If myRng.Rows.Count < 2 Then
Beep 'not enough rows
Exit Sub
End If

ActiveSheet.AutoFilterMode = False

myRng.AutoFilter _
field:=ActiveCell.Column - myRng.Column + 1, _
Criteria1:="<"

End Sub


ddate wrote:

I have recorded a macro but unfortunately it only works for one column. I
would like it to apply to any column and be dependent on what is the active
cell. How do i change this code to do that?

I'm not sure what the field = 24 stands for and what I can replace it with
to make it based on the active cell.

Sub Filter0()
Selection.AutoFilter Field:=24, Criteria1:="<0", Operator:=xlAnd
End Sub


--

Dave Peterson