PC Review


Reply
Thread Tools Rate Thread

Creating Named range problem

 
 
Billy B
Guest
Posts: n/a
 
      9th Nov 2009
I am trying to create a dynamic named range in my Workbook Open event and the
debugger tells me there is a problem. I can't figure it out. Any help would
be appreciated.

Dim sht As Worksheet
sht = "My List"
ActiveWorkBook.Names.Add Name:="KidsNames"
RefersTo:=sht.Offset($A$1,0,0,CountA($A$A),5)

Thank you.
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      9th Nov 2009
Guessing the "My List" is a sheet name, then

Change fromg

sht = "My List"

To

Set sht = Sheets("My List")




"Billy B" <(E-Mail Removed)> wrote in message
news:23DA362C-00B7-4887-95E6-(E-Mail Removed)...
>I am trying to create a dynamic named range in my Workbook Open event and
>the
> debugger tells me there is a problem. I can't figure it out. Any help
> would
> be appreciated.
>
> Dim sht As Worksheet
> sht = "My List"
> ActiveWorkBook.Names.Add Name:="KidsNames"
> RefersTo:=sht.Offset($A$1,0,0,CountA($A$A),5)
>
> Thank you.



 
Reply With Quote
 
B Lynn B
Guest
Posts: n/a
 
      9th Nov 2009
It's a little hard to tell exactly what your range is supposed to be from the
way you wrote the "RefersTo:" string. But say you wanted from $A$1 to the
last used row of column E, this would do it:

Dim myRow As Long
myRow = Sheets("My List").UsedRange.Rows.Count
ActiveWorkbook.Names.Add "KidsNames", _
"='My List'!$A$1:$E$" & myRow

Adjust as needed to get the range you were actually going for.

"Billy B" wrote:

> I am trying to create a dynamic named range in my Workbook Open event and the
> debugger tells me there is a problem. I can't figure it out. Any help would
> be appreciated.
>
> Dim sht As Worksheet
> sht = "My List"
> ActiveWorkBook.Names.Add Name:="KidsNames"
> RefersTo:=sht.Offset($A$1,0,0,CountA($A$A),5)
>
> Thank you.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      10th Nov 2009
You want a name that will refer to that formula--not hard code the address into
the refersto parm, right?

I recorded a macro when I did it manually and got this:

ActiveWorkbook.Names.Add Name:="KidsNames", _
RefersToR1C1:="=OFFSET('My List'!R1C1,0,0,COUNTA('My List'!C1),5)"

Notice that this used referstoR1C1.

You could also use:

ActiveWorkbook.Names.Add Name:="KidsNames", _
RefersTo:="=OFFSET('My List'!$a$1,0,0,COUNTA('My List'!$a:$a),5)"

======
ps. watch those colons in addresses ($a:$a).



Billy B wrote:
>
> I am trying to create a dynamic named range in my Workbook Open event and the
> debugger tells me there is a problem. I can't figure it out. Any help would
> be appreciated.
>
> Dim sht As Worksheet
> sht = "My List"
> ActiveWorkBook.Names.Add Name:="KidsNames"
> RefersTo:=sht.Offset($A$1,0,0,CountA($A$A),5)
>
> Thank you.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating named range in VBA problem Billy B Microsoft Excel Programming 3 22nd Apr 2009 09:41 AM
Problem creating a named range headly Microsoft Excel Programming 7 28th Jul 2008 11:36 AM
creating a filtered range/named range mark kubicki Microsoft Excel Programming 1 4th Nov 2006 03:14 PM
Problem with creating a named range =?Utf-8?B?QWxleA==?= Microsoft Excel Programming 11 9th May 2006 03:41 AM
Can I use named range in data range box when creating pie chart? =?Utf-8?B?QkphY2tzb24=?= Microsoft Excel Charting 2 17th Aug 2005 05:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:22 AM.