Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yes. Something exactly like that.
In article , "DoctorG" wrote: Is there something like Selection.Name="test"? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|