![]() |
Creating a defined name's Refersto range
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 |
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 |
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" |
All times are GMT +1. The time now is 09:27 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com