View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default RANGE NAMES IN MACRO WITH ADVANCED FILTERING

Sub fi() tested
Range("A3:c9").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("e3:e4"), CopyToRange:=Range("h3:j9")
End Sub

Then named the ranges
This worked from ANYWHERE in the workbook, as is, withOUT selections or
goto.

Sub fii()'changed to defined names
Range("NO2") = "NO"
Range("srcrng").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("crrng"), CopyToRange:=Range("dstrng")
End Sub


--
Don Guillett
SalesAid Software

"Ulrik Loves Horses" wrote in
message ...
Advanced Filtering is a great tool while using Macro's.
So far it has been working perfectly with ranges consisting of Cell names
like the example below:
Sheets("2 Air").Select
Application.Goto Reference:="NO2"
ActiveCell.FormulaR1C1 = "NO"
Range("A3:X503").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _
"A531:X532"), CopyToRange:=Range("A536:X636"), Unique:=False
ActiveWindow.SmallScroll Down:=11
ActiveWindow.ScrollWorkbookTabs Position:=xlLast

However I need to make to the ranges variable as number of lines above
will
vary. So I defined the ranges:

A3:X503 as Lines1
A531:X532 as CRIT1
A536:X736 as ADVFILTRES1

I changed the macro as follows:
Sheets("2 Air").Select
Application.Goto Reference:="NO2"
ActiveCell.FormulaR1C1 = "NO"
Range("Lines1").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _
"CRIT1"), CopyToRange:=Range("ADVFILTRES1"), Unique:=False
ActiveWindow.SmallScroll Down:=11
ActiveWindow.ScrollWorkbookTabs Position:=xlLast

RESULT the Macro stops and highlights the AdvancedFilter line.
Range(lines1).xxx or Lines1.xxx or "Lines1".xxx did not improve anything.

Can somebody tell me what I am doing wrong?

Thank you very much for you help. I really appreciate this Discussion
Group.