Okay - based on your sample file, try this:
Sub MakeAllNamedRanges()
Dim vRow As Variant
For Each vRow In Array(1, 9, 16)
Call DefineNamedRanges(CLng(vRow))
Next vRow
End Sub
Sub DefineNamedRanges(lRow As Long)
Dim lCol As Long
Dim stRange As String
With Sheet1
For lCol = 2 To .Cells(lRow, Columns.Count).End(xlToLeft).Column
stRange = .Cells(lRow, lCol).Offset(1, 0).Resize(6, 1).Address(ReferenceStyle:=xlR1C1)
ThisWorkbook.Names.Add _
Name:=Replace(Replace(.Cells(lRow, lCol).Value, " ", ""), "-", "_"), _
RefersToR1C1:="=OFFSET('" & .Name & "'!R" & lRow & "C" & lCol & ",1,0,COUNTA('" & .Name & "'!" & stRange & "),1)"
Next lCol
End With
End Sub
Of course it's possible to run the code once, which will create the dynamic named ranges, then save as a non-macro enabled workbook - the defined named ranges will still exist!
Bookmarks