View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Creating a Dynamic Named Range Using Sheet Name and Column Header

Dim sName As String

sName = Cells(1, ActiveCell.Column).Value
ThisWorkbook.Names.Add Name:=sName & "_Sheet1", _
RefersTo:="=OFFSET(" & sName & "1!" & Cells(2, _
ActiveCell.Column).Address & _
",1,0,COUNTA(" & sName & "!" & _
ActiveCell.EntireColumn.Address & ")-1,1)"

--
Regards,
Tom Ogilvy


"burl_rfc_h" wrote in message
oups.com...
Bob,

I tried your solution, I think it's really close with a few tweaks
(sorry)....

Firstly, ThisWorkbook.Names.Add Name:=sName, _
how can I get it to include the sheet name for example suppose A2 has
Date Machined as the column header and the sheet name is Sheet1
then the range name would be Date_Machined_Sheet1
as a suggestion, do you think it would be best to set the worksheet
name to a variable, then call this out with sName.

Secondly, when I run the macro as written it includes the quotation
marks around the formula
="OFFSET(Sheet1!$A$2,1,0,COUNTA(Sheet1!$A:$A)-1,1)"
only after removing the quoation marks does the dynmanic range work.