Another object defined error!

D

davegb

Am trying to get a properly defined filter range to do an advanced
filter. When I execute "Selection.CurrentRegion.Select" from the
immediate window, it selects exactly what I want. But when I try to set
it as a variable to use for the filter, I get the object not defined
error.

Selection.CurrentRegion.Select
Set RecFltrRange = ActiveWindow.Selection

WkSht.Range(RecFltrRange).AdvancedFilter Action:= _
xlFilterCopy, CriteriaRange:=Sheets("Abuse in Care
Records").Range("aa1:aa2"), _
CopyToRange:=Range("A5"), Unique:=False

Anyone see what I am missing?
Thanks again.
 
T

Tom Ogilvy

Selection.CurrentRegion.Select
Set RecFltrRange = ActiveWindow.Selection

RecFltrRange.AdvancedFilter Action:= _
xlFilterCopy, CriteriaRange:= _
Sheets("Abuse in Care Records").Range("aa1:aa2"), _
CopyToRange:=Range("A5"), Unique:=False

Range("A5") probably needs to be qualified with a sheet reference, but that
would just be a guess.
 
D

davegb

Thanks for your reply, Tom.
It worked fine with just "=range ("a5")" before. For some reason, when
I define the filter range by using CurrentRegion and setting a variable
to that range, it won't accept that in the filter definition. I did
figure out that I was defining the filterrange with the wrong sheet
selected, but don't know why that would give me an object defined
error. I moved the code determining the filter range up to the section
where the correct worksheet was active, but it won't let me select
range ("a1")!!. How can that be?

Set WkSht = ActiveWorkbook.Sheets("Care Records")
With WkSht
.Unprotect Password:=PWORD
.Range("aa2") = CtyCode
.Protect Password:=PWORD
.Range("a1").Select<---Select method failed
End With

Anything else you can see?
 
T

Tom Ogilvy

Set WkSht = ActiveWorkbook.Sheets("Care Records")
With WkSht
.Activate
.Unprotect Password:=PWORD
.Range("aa2") = CtyCode
.Protect Password:=PWORD
.Range("a1").Select<---Select method failed
End With
 
D

davegb

Thanks Tom!

Tom said:
Set WkSht = ActiveWorkbook.Sheets("Care Records")
With WkSht
.Activate
.Unprotect Password:=PWORD
.Range("aa2") = CtyCode
.Protect Password:=PWORD
.Range("a1").Select<---Select method failed
End With
 

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