VB Code Naming a Range (range changes each time)

  • Thread starter Thread starter krazylain
  • Start date Start date
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
 
Selection.Name ="myRange"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
This could work:
ActiveWorkbook.Names.Add Name:="MyRange",
RefersToR1C1:=Sheets(ActiveSheet.Name).Range(ActiveCell.Address)

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

hth
 
Thanks guys..

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

Selection.Name ="myRange"


Thanks..

Krazylai
 
We aim to please.

--

HTH

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top