View Single Post
 
Old 01-25-2022, 10:41 PM
soroush.kalantari soroush.kalantari is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Jun 2021
Posts: 124
soroush.kalantari is on a distinguished road
Default

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
Reply With Quote