Advanced Filter List Range from within a Macro

A

Aaron Vowell

I would like to have a macro perform an advanced filter of my worksheet data. If I perform the filtering manually, the dialog box automatically calculates the list range for me. Is there a way to have the macro caluclate the extent of the list, and then use that information in the advanced filter call? Here's a sample of my code

Sheets("All Issues").Selec
Range("A1").Selec
Range("A1:p729").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=
Range("T1:T2"), Unique:=Fals

I got this code by recording a macro while I performed the advanced filter. I could set the range to something arbitrarily large like P1400, but that method does not seem very sophisticated (to say nothing of having to edit the macro if the list grows beyond 1400 lines). I have not seen an alternative in any of the other postings.

Thanks in advance for your help
Aaron
 
B

Bill Winkle

Hi Aaron.

Sorry about the unrelated response. You're obviously an
expert where I'm a mere novice. Would appreciate your help
in this question that's beyond me:

I have a cell containing a drop-down list box containing 3
values and three other cells next to it, each containing
option buttons. id like to group the cells with option
buttons together and have each button correspond to one of
the values in the drop-down list when checked and show
that value in the cell drop-down cell. hope the ? was
clear. I would REALLY appreciate the help. thanks!

regards,
Bill


-----Original Message-----
I would like to have a macro perform an advanced filter
of my worksheet data. If I perform the filtering
manually, the dialog box automatically calculates the list
range for me. Is there a way to have the macro caluclate
the extent of the list, and then use that information in
the advanced filter call? Here's a sample of my code:
Sheets("All Issues").Select
Range("A1").Select
Range("A1:p729").AdvancedFilter
Action:=xlFilterInPlace, CriteriaRange:= _
Range("T1:T2"), Unique:=False

I got this code by recording a macro while I performed
the advanced filter. I could set the range to something
arbitrarily large like P1400, but that method does not
seem very sophisticated (to say nothing of having to edit
the macro if the list grows beyond 1400 lines). I have
not seen an alternative in any of the other postings.
 
D

Debra Dalgleish

You can use the current region:

Range("A1").CurrentRegion.AdvancedFilter _
Action:=xlFilterInPlace, CriteriaRange:=Range("T1:T2"), _
Unique:=False
 
P

Paulw2k

Hi Aaron

Use the CurrentRegion property . "The current region is a range bounded by
any combination of blank rows and blank columns"(VBA Help file), in other
words your list, however long it may be.

Dim Rng as Range
Sheets("All Issues").Select
Set Rng =Range("A1").CurrentRegion
Rng.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("T1:T2"), Unique:=False

Regards

Paul




Aaron Vowell said:
I would like to have a macro perform an advanced filter of my worksheet
data. If I perform the filtering manually, the dialog box automatically
calculates the list range for me. Is there a way to have the macro
caluclate the extent of the list, and then use that information in the
advanced filter call? Here's a sample of my code:
Sheets("All Issues").Select
Range("A1").Select
Range("A1:p729").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("T1:T2"), Unique:=False

I got this code by recording a macro while I performed the advanced
filter. I could set the range to something arbitrarily large like P1400,
but that method does not seem very sophisticated (to say nothing of having
to edit the macro if the list grows beyond 1400 lines). I have not seen an
alternative in any of the other postings.
 
A

Aaron Vowell

Debra
You certainly know your stuff. Now, my one button macro execution produces some really cool results
Thanks for your help
Aaron
 

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