How to set named range in macro?
I think the problem was that you were setting the worksheet object to be a
named range
Try this
Sub CtyShtFltRng()
Dim lCol As Long
Dim lRow As Long
Dim rCtyShtFltRng As Range
Set rStart = Range("B3")
lRow = rStart.End(xlDown).Row - 1
lCol = rStart.End(xlToRight).Column
Set rCtyShtFltRng = Range(rStart, Cells(lRow, lCol))
ActiveWorkbook.Names.Add Name:="FilterRange",
RefersToR1C1:=rCtyShtFltRng
Range("FilterRange").Select
End Sub
"davegb" wrote in message
oups.com...
I have a macro that is called each time a different sheet in the
workbook is selected. The macro is supposed to define the determined
range as a named ramge, "FilterRange".
Sub CtyShtFltRng()
Dim lCol as Long
Dim lRow As Long
Dim wActSheet As Worksheet
Set wActSheet = ActiveSheet
Set rStart = Range("B3")
lRow = rStart.End(xlDown).Row - 1
lCol = rStart.End(xlToRight).Column
Set rCtyShtFltRng = Range(rStart, Cells(lRow, lCol))
Set wActSheet.Names("FilterRange") = rCtyShtFltRng <---ERROR
wActSheet.Range("FilterRange").Select
End Sub
I'm getting an "wrong number of arguments or invlalid property
assignment" at the marked line. I've tried about 10 or 12 variations on
this line, but none worked. Can someone tell me how to make this work?
Thanks!
|