View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Macro Copy Active Cell to Range Name, loop

If you want to name a cell only, Tom's code is much better. If you want to
name a range of selected cells, I have this to offer:
Sub NameMe()

Dim strName As String
Dim rngMine As Range

'Get text from cell for range name
strName = ActiveCell.Value

'Selects from ActiveCell to 3 cells down in same column
'If you do not always want to do this,
'set up an If statement
Range(ActiveCell, ActiveCell.Offset(3, 0)).Select

'Sets a rnage to the selection and names it
Set rngMine = Selection
ActiveWorkbook.Names.Add _
Name:=strName, _
RefersTo:="=Sheet1!" & rngMine.Address

End Sub

A couple of other items:
-- Tom's code is ALWAYS much better than mine! I offerred this only because
the way I read your post you wanted a range of cells, and Tom's looked like
he only named a single cell. If Tom offers an improvement on this, go with
that one.
-- You do not "move to the name box" as you would move from cell to cell.
You access the Names collection of the Workbook and Add a name.
-- You will find a lot of answers faster than waiting for posts on the
newsgroup by working through the Help files in the VBA editor. You can type
a key word or two describing what you want to do ( such as "name cells") in
the Answer Wizard, and it will give you a list of topics. It's often a lot
to wade through, but you'll get farther than you will by sitting and
waiting. Another highly recommended way is a Google search of the
newsgroup. Ron DeBruin has created an excellent Add-In that I use all the
time - http://www.rondebruin.nl/Google.htm.

Ed
(PS - I'm offline now for about 18 hours, so I won't be able to answer
anything else for a while.)

wrote in message
oups.com...
Thanks so much Ed.

One more question. Say I wanted to
1. copy the data from the active cell
2. select from the active cell to 3 rows down
3. move to the name box and paste the copied data, thus naming the
range what was in the initial active.cell

Thanks!!!!!