Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Naming a Range with VB

I have a loop that I run through where the name of the
CurrentRange variable changes each time through.

For example, if the CurrentRange variable is "Justin's
Range" and the CurrentSheet variable is "Justin's Sheet",

I want to name the range, "Justin's Range", with the
following formula:

"=OFFSET("Justin's Sheet"!$A$1,0,0,
COUNTA("Justin's Sheet"!$A$1:$A$365),1)"

This is the code I'm using:

ActiveWorkbook.Names.Add Name:=CurrentRange,
RefersToR1C1:= _
"=OFFSET(CurrentSheet!$A$1,0,0,
COUNTA(CurrentSheet!$A$1:$A$365),1)"

I think it's trying to find a sheet called "CurrentSheet"
instead of computing the formula out.

Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Naming a Range with VB

ActiveWorkbook.Names.Add Name:=CurrentRange,
RefersToR1C1:= _
"=OFFSET('" & Activesheet.Name & "'!$A$1,0,0,
COUNTA('" & ActiveSheet.Name & "'!$A$1:$A$365),1)"

Note the addition of single quotes on each side of ActiveSheet.Name since
the sheet name could contain spaces.

--
Regards,
Tom Ogilvy


"Justin" wrote in message
...
I have a loop that I run through where the name of the
CurrentRange variable changes each time through.

For example, if the CurrentRange variable is "Justin's
Range" and the CurrentSheet variable is "Justin's Sheet",

I want to name the range, "Justin's Range", with the
following formula:

"=OFFSET("Justin's Sheet"!$A$1,0,0,
COUNTA("Justin's Sheet"!$A$1:$A$365),1)"

This is the code I'm using:

ActiveWorkbook.Names.Add Name:=CurrentRange,
RefersToR1C1:= _
"=OFFSET(CurrentSheet!$A$1,0,0,
COUNTA(CurrentSheet!$A$1:$A$365),1)"

I think it's trying to find a sheet called "CurrentSheet"
instead of computing the formula out.

Any help would be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Naming a Range with VB

Thanks for your response.

-----Original Message-----
ActiveWorkbook.Names.Add Name:=CurrentRange,
RefersToR1C1:= _
"=OFFSET('" & Activesheet.Name & "'!$A$1,0,0,
COUNTA('" & ActiveSheet.Name & "'!$A$1:$A$365),1)"

Note the addition of single quotes on each side of

ActiveSheet.Name since
the sheet name could contain spaces.

--
Regards,
Tom Ogilvy


"Justin" wrote in

message
...
I have a loop that I run through where the name of the
CurrentRange variable changes each time through.

For example, if the CurrentRange variable is "Justin's
Range" and the CurrentSheet variable is "Justin's

Sheet",

I want to name the range, "Justin's Range", with the
following formula:

"=OFFSET("Justin's Sheet"!$A$1,0,0,
COUNTA("Justin's Sheet"!$A$1:$A$365),1)"

This is the code I'm using:

ActiveWorkbook.Names.Add Name:=CurrentRange,
RefersToR1C1:= _
"=OFFSET(CurrentSheet!$A$1,0,0,
COUNTA(CurrentSheet!$A$1:$A$365),1)"

I think it's trying to find a sheet

called "CurrentSheet"
instead of computing the formula out.

Any help would be appreciated.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming a Data Range NotaTechy Excel Discussion (Misc queries) 2 February 6th 10 10:01 PM
Naming a range hello Excel Discussion (Misc queries) 3 May 7th 07 07:01 PM
Range naming Squeaky Excel Discussion (Misc queries) 2 December 29th 06 09:10 PM
Naming a range bob777 Excel Discussion (Misc queries) 1 February 1st 06 01:05 PM
Range naming BigJim Excel Programming 5 December 2nd 03 01:06 PM


All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"