VB Code Naming a Range (range changes each time)

K

krazylain

Can somehere tell me how to name a range in excel using VB code. Here'
how I get the range:

Range("L1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False


As u can see the range changes, but I would like to create the sam
name for whatever the range is?

Thanks..
Krazylai
 
B

Bob Phillips

Selection.Name ="myRange"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
S

steveb

This could work:
ActiveWorkbook.Names.Add Name:="MyRange",
RefersToR1C1:=Sheets(ActiveSheet.Name).Range(ActiveCell.Address)

(watch for word-wrap, should be one line)

hth
 
K

krazylain

Thanks guys..

Never used this vb command before, but this is exactly what I wanted.

Selection.Name ="myRange"


Thanks..

Krazylai
 
B

Bob Phillips

We aim to please.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top