Hi,
I’ve recorded a macro to run a filter (as below) it and it works fine. The only problem I have is that sometimes a column will be added, or possibly removed from the sheet - meaning the filter won’t always work. Is there a way to make sure the filter always does what it does on the same column, regardless of any changes to the column's location?
Sub late() ' ' late Macro ' ' Range("J8:J11").Select Selection.AutoFilter ActiveSheet.Range("$B$8:$J$94").AutoFilter Field:=9, Criteria1:="=*late*", _ Operator:=xlAnd End Sub
Last edited by Barking_Mad; 07-21-2010 at 08:17 AM.
Hi Barking_Mad,
Possibly if you know the field title eg if the coulmn title is "Two"
x=application.worksheetfunction.MATCH("Two",A7:z7,0) ActiveSheet.Range("$B$8:$J$94").AutoFilter Field:=x, Criteria1:="=*......
Last edited by pike; 07-16-2010 at 07:33 AM.
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
Hi Pike,
Thanks, but im having trouble getting the compiler to accept the code....im crap at VBA so please excuse..It's giving me a synstax error
Additionally, should i deletex=application.worksheetfunction.MATCH("Two", A7:z7,0)
from the original code?Range("J8:J11").Select Selection.AutoFilter
Hi Barking_Mad
Could you attach the workbook?
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
Here you go, ive taken bits and pieces of sensitive info out, but the column i want to filter is the ANNOTATIONS one on the end of the sheet, namely anything with LATE in the column of cells..
Dude try this...
Option Explicit Sub tester() Dim xCount As Long xCount = Application.WorksheetFunction.Match("Annotations", Range("A8:z8"), 0) With Cells(8, xCount) ActiveSheet.Range("B8:" & Chr(xCount + 64) & "94").AutoFilter Field:=xCount - 1, Criteria1:="=*late*" End With End Sub
Last edited by pike; 07-16-2010 at 08:07 PM. Reason: xcount added
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
Barkingmad
also removed the merged cells
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
Thanks Pike![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks