I define a dynamic named range with
Worksheets("Cleaned").Names.Add Name:="Date", RefersToR1C1:="=Cleaned!R2C2:INDEX(Cleaned!C2, COUNTA(Cleaned!C2))"
Before execution of the following loop a watch Worksheets("Cleaned").Range("Date").Address shows that the range is $B$1:$B$2
For I = 2 To NRows
Worksheets("Cleaned").Range("Date").Cells(I).NumberFormat = "yyyy-mm-dd"
Worksheets("Cleaned").Range("Date").Cells(I) = Worksheets("Cleaned").Range("Date_and_Time").Cells(I - 1)
... other instructions which do not influence this problem. The changes described below occur after the execution of the statement above.
Next I
After the first iteration the correct cell of Date_and_Time is copied to the correct cell in Date (Cell A2 copied to B2). The watch shows range $B$2
After the second iteration the correct cell of Date_and_Time is copied to a cell under the targeted cell in Date (Cell A2 copied to B3). The watch shows range $B$2:$B$3
After the third iteration thec orrect cell of Date_and_Time is copied to a cell under the targeted cell in Date (Cell A3 copied to B4.) The watch shows range $B$2:$B$4
Next iteration continue to do the same: copying the correct cell to a cell under the targeted cell
Why is the range changed to $B$2 after the first iteration. I would expect it to be $B$2:$B$3. What error dit I make?
Worksheets("Cleaned").Names.Add Name:="Date", RefersToR1C1:="=Cleaned!R2C2:INDEX(Cleaned!C2, COUNTA(Cleaned!C2))"
Before execution of the following loop a watch Worksheets("Cleaned").Range("Date").Address shows that the range is $B$1:$B$2
For I = 2 To NRows
Worksheets("Cleaned").Range("Date").Cells(I).NumberFormat = "yyyy-mm-dd"
Worksheets("Cleaned").Range("Date").Cells(I) = Worksheets("Cleaned").Range("Date_and_Time").Cells(I - 1)
... other instructions which do not influence this problem. The changes described below occur after the execution of the statement above.
Next I
After the first iteration the correct cell of Date_and_Time is copied to the correct cell in Date (Cell A2 copied to B2). The watch shows range $B$2
After the second iteration the correct cell of Date_and_Time is copied to a cell under the targeted cell in Date (Cell A2 copied to B3). The watch shows range $B$2:$B$3
After the third iteration thec orrect cell of Date_and_Time is copied to a cell under the targeted cell in Date (Cell A3 copied to B4.) The watch shows range $B$2:$B$4
Next iteration continue to do the same: copying the correct cell to a cell under the targeted cell
Why is the range changed to $B$2 after the first iteration. I would expect it to be $B$2:$B$3. What error dit I make?