Advanced Filtering in VBA

J

John Pierce

I would like to make this procedure more flexible by using relative
references
rather than absolute cell references. The first version works
perfectly but I can't get the second version to work. It always
results in all lines disappearing. I know this may be difficult to
resolve without seeing the sheet it is used on but perhaps there is
just a basic coding error. Thanks in advance
for any help.

Public Sub LedgerView()
'
Range("A5").Select
Range("A6:G260").AdvancedFilter _
Action:=xlFilterInPlace, CriteriaRange:=Range("B1:D3"),
Unique:=False
Range("A5").Select

' Range("A6").Select
' Range(Selection, Selection).CurrentRegion.Select
' Selection.AdvancedFilter _
' Action:=xlFilterInPlace, CriteriaRange:=Range("B1:D3"),
Unique:=False
' Range("A5").Select

End Sub
 
T

Tim Barlow

John,

It worked for me - but you could simplify the code to:

Public Sub LedgerView()

Range("A6").CurrentRegion.AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("B1:D3"), _
Unique:=False

End Sub

Tim
 

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