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.

RE: Variable length named ranges by James_Thomlinson

James_Thomlinson
Thu May 08 12:14:01 CDT 2008

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.
>

Re: Variable length named ranges by Jeff

Jeff
Thu May 08 12:58:11 CDT 2008

"Jim Thomlinson" <James_Thomlinson@owfg-Re-Move-This-.com> wrote in message
news:9312ABE6-AF92-408D-82E8-7D94E5B7B35B@microsoft.com...

>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....



Re: Variable length named ranges by Peter

Peter
Thu May 08 13:56:37 CDT 2008

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" <adimar@discussions.microsoft.com> wrote in message
news:32877950-A143-423E-859D-D83C50CC19E4@microsoft.com...
> 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.
>