ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Naive question on Range naming but please answer (https://www.excelbanter.com/excel-programming/342342-naive-question-range-naming-but-please-answer.html)

DoctorG

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

JE McGimpsey

Naive question on Range naming but please answer
 
Yes. Something exactly like that.

In article ,
"DoctorG" wrote:

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


K Dales[_2_]

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


DoctorG

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...

Mike Fogleman

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




Tom Ogilvy

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




DoctorG

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?

Tom Ogilvy

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?





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com