Macro to select all and name range

  • Thread starter Thread starter Richard H Knoff
  • Start date Start date
R

Richard H Knoff

I have a workbook with some macros that work on another workbook
("Data.xls"). One thing I want the macro to do, is to select everything in
a worksheet named Survey and name the range "Database". This would be
equivalent to go to the Data workbook and Survey worksheet, hitting
Ctrl+Shift+End and enter Database in the name box. I can't record this
action because the code specifies the cells included in the current version
of Data.xls, and the number of rows will change.
What code can I use to accomplish this?

Richard
 
Richard,

Try this

With Workbooks("Data.xls")
.Names.Add Name:="Database", RefersTo:="=" &
..Worksheets("Survey").Name & "!" & _

..Worksheets("Survey").Range("A1").CurrentRegion.Address
End With


--

HTH

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

Workbooks("Data.xls").Sheets("Survey").Range( _
"A1").CurrentRegion.Name = "Database"
 
Thanks, Bob. I don't quite understand the first part yet, but I'll work on
it!

Richard
 
Back
Top