ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variable length named ranges (https://www.excelbanter.com/excel-programming/410649-variable-length-named-ranges.html)

adimar

Variable length named ranges
 
I need a way to specify a variable for the last row in a named range.

A static definition looks like this:
ThisWorkbook.Names.Add Name:="dAge", RefersTo:="=RawData!$H$2:$H$100",
Visible:=True

I would like to replace €œ100€ with €œnRows€ and need help with the syntax.


Thank you.


Jim Thomlinson

Variable length named ranges
 
I assume that nRows is an integer or long variable...

ThisWorkbook.Names.Add Name:="dAge", RefersTo:="=RawData!$H$2:$H$" & nRows,
Visible:=True

--
HTH...

Jim Thomlinson


"adimar" wrote:

I need a way to specify a variable for the last row in a named range.

A static definition looks like this:
ThisWorkbook.Names.Add Name:="dAge", RefersTo:="=RawData!$H$2:$H$100",
Visible:=True

I would like to replace €œ100€ with €œnRows€ and need help with the syntax.


Thank you.


Jeff Johnson[_2_]

Variable length named ranges
 
"Jim Thomlinson" wrote in message
...

I assume that nRows is an integer or long variable...

ThisWorkbook.Names.Add Name:="dAge", RefersTo:="=RawData!$H$2:$H$" &
nRows,
Visible:=True


I hope the poster understands that the named range is not "connected" to
nRows, i.e., if the value of nRows changes later it won't change the range
that was just created. Just thought I'd mention it....



Peter T

Variable length named ranges
 
In addition to other replies do you really mean to add the name to
"ThisWorkbook". From what you followed up with in your other recent I
suspect you mean ActiveWorkbook or some other named wb.

Regards,
Peter T

"adimar" wrote in message
...
I need a way to specify a variable for the last row in a named range.

A static definition looks like this:
ThisWorkbook.Names.Add Name:="dAge", RefersTo:="=RawData!$H$2:$H$100",
Visible:=True

I would like to replace "100" with "nRows" and need help with the syntax.


Thank you.





All times are GMT +1. The time now is 06:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com