View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Adding Range Names

Tom,

I've figured out the problem. Your responses were very helpful in doing
that. Thanks,

Barb Reinhardt

"Tom Ogilvy" wrote:

All I can do is demonstrate the mechanics in the immediate window, which
worked fine for me:

rangename = "chtlen"
seriesrange = 12
ActiveWorkbook.Names.Add Name:= rangename, RefersToR1C1:="=" & seriesrange
? activeworkbook.Names(rangename).Name
chtlen
? activeworkbook.Names(rangename).RefersTo
=12
Activeworkbook.Names.Add Name:="ActItms_ChartLabel", _

Refersto:="=OFFSET(ActItms!$B$33,0,0,1,min(chtlen, COUNTA(ActItms!$33:$33)))"
? activeworkbook.Names("ActItms_ChartLabel").Name
ActItms_ChartLabel
?
activeworkbook.Names("ActItms_ChartLabel").RefersT oRange.Address(0,0,xlA1,Tr
ue)
[Book1]ActItms!B33:M33

--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
Let me clarify this:
A2:chtlen
B2:=12
A3:ActItms_ChartLabel
B3:=OFFSET(ActItms!$B$33,0,0,1,min(chtlen,COUNTA(A ctItms!$33:$33)))

"Barb Reinhardt" wrote:

I'm now getting a runtime error:
A B
2 chtlen =12
3 ActItms_ChartLabel
=OFFSET(ActItms!$B$33,0,0,1,min(chtlen,COUNTA(ActI tms!$33:$33)))

The error is on the following line:

ActiveWorkbook.Names.Add Name:=rangename, RefersToR1C1:="=" &

seriesrange

"Tom Ogilvy" wrote:

I would have thought you would need to do:

ActiveWorkbook.Names.Add Name:= rangename, RefersToR1C1:="=" &

seriesrange

if that is what you wanted to do.

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in

message
...
I now have the following:

Dim lastrow
Dim rangename
Dim seriesrange
Dim CurBook
Dim i

CurBook = Application.ActiveWorkbook.Name
lastrow = Worksheets("RangeName").Cells(Rows.Count,

"a").End(xlUp).Row
Debug.Print lastrow
For i = 2 To lastrow
rangename = Workbooks(CurBook).Worksheets("RangeName").Range(" a"

&
i).Value
seriesrange =

Workbooks(CurBook).Worksheets("RangeName").Range(" b" &
i).Value
Debug.Print rangename; seriesrange
ActiveWorkbook.Names.Add Name:="=" & rangename,
RefersToR1C1:=seriesrange
Next

A2: chtlen
B2: '=12

Thanks,
Barb