Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Naive question on Range naming but please answer

Is there an easy way to set the Name Property for a range when I have it
selected in code?
i.e.
Range("D_DATABASE_START").Select
Range(Selection, Selection.End(xlDown)).Select

I tried to figure this out by recording the moves involved but the resulting
macro code states the following : ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Data!R2C1:R9C8"

I wish to avoid the R1C1 part by something that relies on the fact that the
range is already selected in code.

Is there something like Selection.Name="test"?
Please help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Naive question on Range naming but please answer

Yes. Something exactly like that.

In article ,
"DoctorG" wrote:

Is there something like Selection.Name="test"?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Naive question on Range naming but please answer

ActiveWorkbook.Names.Add Name:="test", RefersTo:="=" & Selection.Address
--
- K Dales


"DoctorG" wrote:

Is there an easy way to set the Name Property for a range when I have it
selected in code?
i.e.
Range("D_DATABASE_START").Select
Range(Selection, Selection.End(xlDown)).Select

I tried to figure this out by recording the moves involved but the resulting
macro code states the following : ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Data!R2C1:R9C8"

I wish to avoid the R1C1 part by something that relies on the fact that the
range is already selected in code.

Is there something like Selection.Name="test"?
Please help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Naive question on Range naming but please answer

Okay, this is a bit embarassing, but thanks anyway...

I used to get an 1004 run-time error... don't know why... but I tried my own
solution and it worked.

I guess I will just find comfort in the thought that what looked reasonable
to do was actually right. Oh well...
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Naive question on Range naming but please answer

This should do it:
Sub test()
With Application.Selection
ActiveWorkbook.Names.Add Name:="Test", _
RefersTo:=Application.Selection
End With
End Sub

Mke F
"DoctorG" wrote in message
...
Is there an easy way to set the Name Property for a range when I have it
selected in code?
i.e.
Range("D_DATABASE_START").Select
Range(Selection, Selection.End(xlDown)).Select

I tried to figure this out by recording the moves involved but the
resulting
macro code states the following : ActiveWorkbook.Names.Add
Name:="test",
RefersToR1C1:="=Data!R2C1:R9C8"

I wish to avoid the R1C1 part by something that relies on the fact that
the
range is already selected in code.

Is there something like Selection.Name="test"?
Please help





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Naive question on Range naming but please answer

I would suggest an expanded address

ActiveWorkbook.Names.Add Name:="test", RefersTo:="=" &
Selection.Address(true,true,xlA1,true)

assuming the worksheet is in A1 mode.

--
Regards,
Tom Ogilvy

"K Dales" wrote in message
...
ActiveWorkbook.Names.Add Name:="test", RefersTo:="=" & Selection.Address
--
- K Dales


"DoctorG" wrote:

Is there an easy way to set the Name Property for a range when I have it
selected in code?
i.e.
Range("D_DATABASE_START").Select
Range(Selection, Selection.End(xlDown)).Select

I tried to figure this out by recording the moves involved but the

resulting
macro code states the following : ActiveWorkbook.Names.Add

Name:="test",
RefersToR1C1:="=Data!R2C1:R9C8"

I wish to avoid the R1C1 part by something that relies on the fact that

the
range is already selected in code.

Is there something like Selection.Name="test"?
Please help



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Naive question on Range naming but please answer

You have all given me varying approaches to the same issue, some more
thorough than others, instead of the Selection.Name="TEST" which is indeed
very simple yet effective, at least in this case.
You are all obviously experienced programmers so I will ask you if there is
a need to use a more elaborate piece of code in order to achieve consistent
results. Does the simplistic Selection.Name approach work by coincidence
here?
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Naive question on Range naming but please answer

Selection.Name = "Test"

is indeed the most efficient and effective. It obviates the shortcoming of
not specifying the sheet name found in the other suggestions. So JE
McGimsey's suggestion is consistent, effective and highly recommended.

--
Regards,
Tom Ogilvy

"DoctorG" wrote in message
...
You have all given me varying approaches to the same issue, some more
thorough than others, instead of the Selection.Name="TEST" which is indeed
very simple yet effective, at least in this case.
You are all obviously experienced programmers so I will ask you if there

is
a need to use a more elaborate piece of code in order to achieve

consistent
results. Does the simplistic Selection.Name approach work by coincidence
here?



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 an answer in a formula T-bart Excel Discussion (Misc queries) 1 January 18th 08 02:56 AM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 03:24 AM.

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

About Us

"It's about Microsoft Excel"