View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ulrik loves horses Ulrik loves horses is offline
external usenet poster
 
Posts: 11
Default RANGE NAMES IN MACRO WITH ADVANCED FILTERING

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.