Creating a defined name's Refersto range
To start with, you cannot have 0 columns or rows when using resize.
Change the 0 to 1
Workbooks("Book1.xlsb").Names.Add Name:="Test", _
RefersTo:=Sheets("Sheet1").Range("A1").Resize(r - 1, 1)
Second...........your Resize(r - 1, 1) will return A1:A4 when r = 5
Third.........subscript out of range error usually means no such
workbook or worksheet.
Gord
On Tue, 13 Mar 2012 20:37:31 -0400, "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
|