Dynamic Advanced FilterJun 21, 2006
I am trying to create a function using vba and the advanced filter function.
The spreadsheet I am using changes from week to week so it can have different amounts of columns and also rows.
This is my code.
Dim rngToFilter As Range
Dim rngFilterCriteria As Range
Dim LastRow As Long, LastCol As Integer
With Sheets("Main FTE")
Range("b2000").Value = "Cost Code"
Range("b2001").Value = "5*"
It works ok if I have values in columns A:X but if for example I only have information in A:S I get a runtime error.
I know how to find the last column and last row by using
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
LastCol = Range("IV1").End(xlToLeft).Column
But I don't know how to modify my code to use these.