Thank you very much. Inspired with your response, I modified my code as follow and that solved my problem.
Sub dynamicrange()
Dim rng As Range
Dim n As Integer
Dim myrow As Integer
Dim cell As Range
Dim cell02 As Range
Dim cellAddress As String
Dim cellAddress02 As String
myname = ActiveCell.Value
myrow = ActiveCell.Row
Set cell = ActiveCell
cellAddress = cell.Parent.Name & "!" & cell.address(1, 0)
Set cell02 = Range("A1")
cellAddress02 = cell02.Parent.Name & "!" & cell02.address(1, 0)
ActiveWorkbook.Names.Add Name:=ActiveCell.Value, RefersTo:="=" & "INDEX(" & cellAddress02 & ":" & cellAddress & "," & myrow & ")"
End Sub
|