Advanced Filter to Dynamic Range

J

John

I've applied an Advanced Filter to a Range and simply recorded the macro,
extract below, but my problem is that my data in the Database sheet is
dynamic and changes in Row length (not by column)

How can I incorporate a dynamic range via VBA with Advanced Filters?

Thanks



Sheets("Database").Select
Range("A1:T61").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _
"V1:V2"), CopyToRange:=Range("X1:AQ1"), Unique:=False
Range("A1").Select
 
T

Tom Ogilvy

Sheets("Database").Select
Range("A1").CurrentRegion.AdvancedFilter _
Action:=xlFilterCopy,
CriteriaRange:=Range("V1:V2"), _
CopyToRange:=Range("X1:AQ1"), Unique:=False
Range("A1").Select
 
N

Nigel

Dim LastRow as Long
LastRow = Sheets("Database").Cells(Rows.Count,1).End(xlup).Row


With Sheets("Database").Select
Range("A1:T" & LastRow).AdvancedFilter Action:=xlFilterCopy,

CriteriaRange:=Range( _
"V1:V2"), CopyToRange:=Range("X1:AQ1"), Unique:=False
Range("A1").Select
 
J

John

Thanks Guys

Nigel said:
Dim LastRow as Long
LastRow = Sheets("Database").Cells(Rows.Count,1).End(xlup).Row


With Sheets("Database").Select
Range("A1:T" & LastRow).AdvancedFilter Action:=xlFilterCopy,

CriteriaRange:=Range( _
"V1:V2"), CopyToRange:=Range("X1:AQ1"), Unique:=False
Range("A1").Select
 
J

John

Guys I'm getting a syntax error on both your codes, am I missing something?
Where does the 'CurrentRegion' come from?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top