My code runs but MATCH('Worksheets1'!$D2,
is not changing or updating based on the the row it is at.
For example if my worksheet contains 2000 rows to be index matched the formula will still just contain MATCH('Worksheets1'!$D2
as the cell it is referencing .
How do I make the cell value change based on what what row number the code is at?
Sub trial()
On Error Resume Next
Dim Dept_Row As Long
Dim Dept_Clm As Long
Table1 = Worksheets1.Range("D:D")
Table2 = Worksheets2.Range("A:B")
Dept_Row = Worksheets1.Range("A2").Row
Dept_Clm = Worksheets1.Range("A2").Column
For Each cl In Table1
If IsEmpty(cl) Then Exit Sub
If Not IsEmpty(cl) Then Worksheets("Worksheets1").Cells(Dept_Row, Dept_Clm) = _
"=INDEX('Worksheets2'!$B:$B,MATCH('Worksheets1'!$D2,'Worksheets2'!A:A,0)) "
Dept_Row = Dept_Row + 1
Next cl
Exit Sub
I created the loop in hopes of the formula updating giving it the
Dept_Row = Dept_Row + 1.
I tried both leaving it where it is, and introducing the code to quotation marks after the formula ended. However, my code is only able to run as is.
I was thinking of doing plus 1 but I doubted that would work it would just turn the cell value of D2 into D3 for all.