Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Creating Named Ranges in VBA

All,

Using Excel 2000, I'm unable to programmatically create a named range. I
have a series of lookup tables which I export from a database to an Excel
spreadsheet (all standard code/description-type lookup tables). I then want
to create a named range for each lookup table's data. I've tried both the
following methods and, while neither generates an error, they do not create
the named range:

1. MyWorksheet.Names.Add Name:="NewRangeName", RefersToR1C1:="R1C1:R14:C2"

2. Range(Cells(1, 1), Cells(14, 2)).Name = "NewRangeName"

Any ideas?

Thanks,

Mark D'Agosta




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Creating Named Ranges in VBA

Put an equals within the RefersTo double-quotes, like this:

RefersToR1C1:="=R1C1:R14:C2"

Bill Barclift

"Mark D'Agosta" wrote in message
et...
All,

Using Excel 2000, I'm unable to programmatically create a named range. I
have a series of lookup tables which I export from a database to an Excel
spreadsheet (all standard code/description-type lookup tables). I then

want
to create a named range for each lookup table's data. I've tried both the
following methods and, while neither generates an error, they do not

create
the named range:

1. MyWorksheet.Names.Add Name:="NewRangeName",

RefersToR1C1:="R1C1:R14:C2"

2. Range(Cells(1, 1), Cells(14, 2)).Name = "NewRangeName"

Any ideas?

Thanks,

Mark D'Agosta






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating Named Ranges in VBA

With Worksheets("Sheet1")
.Range(.Cells(1, 1), .Cells(14, 2)).Name = "NewRangeName"
End With
msgbox Range("NewRangeName").address(External:=True")

should work. It always does for me.

You don't have "on error resume next" set in your code do you?

--
Regards,
Tom Ogilvy

Mark D'Agosta wrote in message
et...
All,

Using Excel 2000, I'm unable to programmatically create a named range. I
have a series of lookup tables which I export from a database to an Excel
spreadsheet (all standard code/description-type lookup tables). I then

want
to create a named range for each lookup table's data. I've tried both the
following methods and, while neither generates an error, they do not

create
the named range:

1. MyWorksheet.Names.Add Name:="NewRangeName",

RefersToR1C1:="R1C1:R14:C2"

2. Range(Cells(1, 1), Cells(14, 2)).Name = "NewRangeName"

Any ideas?

Thanks,

Mark D'Agosta






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Creating Named Ranges in VBA

Tom,

Yes, I did have "on error resume next" set! Earlier in the procedure I
wanted to clear a range that may or may not exist, so I turned off the error
handler... and forgot to turn it back on! Working much better now. Thanks.

Mark

"Tom Ogilvy" wrote in message
...
With Worksheets("Sheet1")
.Range(.Cells(1, 1), .Cells(14, 2)).Name = "NewRangeName"
End With
msgbox Range("NewRangeName").address(External:=True")

should work. It always does for me.

You don't have "on error resume next" set in your code do you?

--
Regards,
Tom Ogilvy

Mark D'Agosta wrote in message
et...
All,

Using Excel 2000, I'm unable to programmatically create a named range.

I
have a series of lookup tables which I export from a database to an

Excel
spreadsheet (all standard code/description-type lookup tables). I then

want
to create a named range for each lookup table's data. I've tried both

the
following methods and, while neither generates an error, they do not

create
the named range:

1. MyWorksheet.Names.Add Name:="NewRangeName",

RefersToR1C1:="R1C1:R14:C2"

2. Range(Cells(1, 1), Cells(14, 2)).Name = "NewRangeName"

Any ideas?

Thanks,

Mark D'Agosta








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Creating Named Ranges in VBA

Bill,

Thanks for the tip. It did the trick. So now that I got two replies to
this post, I have two different methods I can use to programmatically create
my named range.

Thanks for your help.

Mark


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
Problem creating named ranges in a Macro! LABKHAND Excel Discussion (Misc queries) 2 January 8th 10 04:58 PM
Creating dynamic ranges which are named. U0107 Excel Worksheet Functions 1 January 5th 10 11:46 PM
Using named 3-D ranges Nick S. Excel Discussion (Misc queries) 1 March 22nd 07 11:26 AM
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
Named Ranges Gary T Excel Worksheet Functions 2 December 27th 04 02:28 AM


All times are GMT +1. The time now is 07:59 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"