View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_2_] Don Guillett[_2_] is offline
external usenet poster
 
Posts: 1,522
Default Creating a defined name's Refersto range

On Tuesday, March 13, 2012 7:37:31 PM UTC-5, kittronald wrote:
I'm trying to create a defined name's Refersto range of
"Sheet1!$A$1:$A$5" using the variable below.

r = 5

Workbooks("Book1.xlsb").Names.Add Name:="Test",
RefersTo:=Sheets("Sheet1").Range("A1").Resize(r - 1, 0)

This doesn't work and gives a Run-time error '9': Subscript out of range
error.

What is the code to get the Refersto range properly setup ?


kittronald


Another way, assuming same file

r=5
sheets("sheet1").range("a1").resize(r-1).name="Test"