Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default How to define a Named Range in VBA?

I'm trying to define a named range in VBA using the following syntax.
However, it gives me an error regarding the equal sign and if I remove the
equal sign, then the named range is defined but it treats the formula as a
text value so it doesn't evaluate it. I'm sure there's something easy that
I'm overlooking but what is it?

Any help is appreciated.

ActiveWorkbook.Names.Add Name:="PivotRange", RefersToR1C1:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) '"

--
Richard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to define a Named Range in VBA?

You can't use A1 notation in an R1C1 formula, and you have a spurious '

ActiveWorkbook.Names.Add Name:="PivotRange", RefersTo:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) "


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Richard" wrote in message
...
I'm trying to define a named range in VBA using the following syntax.
However, it gives me an error regarding the equal sign and if I remove the
equal sign, then the named range is defined but it treats the formula as a
text value so it doesn't evaluate it. I'm sure there's something easy

that
I'm overlooking but what is it?

Any help is appreciated.

ActiveWorkbook.Names.Add Name:="PivotRange", RefersToR1C1:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) '"

--
Richard



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to define a Named Range in VBA?

The OP also has a typo in the countA argument (assuming Shee1 should be
Sheet1)

ActiveWorkbook.Names.Add Name:="PivotRange", RefersTo:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!A:A),10 )"

--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
You can't use A1 notation in an R1C1 formula, and you have a spurious '

ActiveWorkbook.Names.Add Name:="PivotRange", RefersTo:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) "


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Richard" wrote in message
...
I'm trying to define a named range in VBA using the following syntax.
However, it gives me an error regarding the equal sign and if I remove

the
equal sign, then the named range is defined but it treats the formula as

a
text value so it doesn't evaluate it. I'm sure there's something easy

that
I'm overlooking but what is it?

Any help is appreciated.

ActiveWorkbook.Names.Add Name:="PivotRange", RefersToR1C1:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) '"

--
Richard





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default How to define a Named Range in VBA?

Thank you both for the quick responses. The typo was my error as I replaced
the actual name w/ Sheet1 for simplicity purposes when posting. The R1C1
reference I was not aware of but makes perfect sense.

I've fixed my code and it works fine. Thanks again!!
--
Richard


"Tom Ogilvy" wrote:

The OP also has a typo in the countA argument (assuming Shee1 should be
Sheet1)

ActiveWorkbook.Names.Add Name:="PivotRange", RefersTo:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!A:A),10 )"

--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...
You can't use A1 notation in an R1C1 formula, and you have a spurious '

ActiveWorkbook.Names.Add Name:="PivotRange", RefersTo:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) "


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Richard" wrote in message
...
I'm trying to define a named range in VBA using the following syntax.
However, it gives me an error regarding the equal sign and if I remove

the
equal sign, then the named range is defined but it treats the formula as

a
text value so it doesn't evaluate it. I'm sure there's something easy

that
I'm overlooking but what is it?

Any help is appreciated.

ActiveWorkbook.Names.Add Name:="PivotRange", RefersToR1C1:= _
"=OFFSET(Sheet1!$A$1,0,0,COUNTA(Shee1!A:A),10) '"

--
Richard






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
How do I have a cell value define a dynamic named range? CellShocked Excel Worksheet Functions 15 October 26th 11 02:08 AM
How to Define a named Formula at the Worksheet level? RPJ Excel Worksheet Functions 2 October 22nd 06 05:11 PM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
Automatically define series of named ranges Jon Tillman Excel Programming 7 June 18th 04 07:39 AM
Help with named constants in Define Name dialog box!!!! ilona Excel Programming 3 May 1st 04 12:01 AM


All times are GMT +1. The time now is 01:59 PM.

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"