View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bert[_2_] Bert[_2_] is offline
external usenet poster
 
Posts: 13
Default Variable as argument in filter range

I'm trying to use the following to do filtering of a list of changing
length.
x = LastRow() ' this is a function that returns the last row in the
current list
Rng = "$A$2:$C$" & Trim(Str(x)) ' this concatenates that number to a
variable to
Range("A2").Select ' this sets the selection at the top of the list.

' from what I can determine the following to lines should be identical. BUT
the one with the variable causes an error.
' while the second line works fine.

Range(Rng).AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("I2:I3"), CopyToRange:=Range("M1:O1"), Unique:=False

Range("A1:C119").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range("I2:I3"), CopyToRange:=Range("M1:O1"), Unique:=False

I've tried creating Rng to equal "$A$2:$C$119" and tried
Range(Cells(2,1),Cells(x,3)) all with the same error: "Run-time error 1004.
The extract range has a missing or illegal field name."

Any suggestions would be appreciated.
Thanks
Bert