I have vb code set up to add a vlookup formula to the activecell. I was trying to add a For Each In Next loop to it so that it would populate the range with the relative formula, but instead it returning exactly the same formula for each and every cell within the range.
Sub Lookup_Formula()
Dim a$, c$, e$, f$
Dim r As Range
Set r = ActiveCell
a = r.Offset(0, -4).Value
b = r.Column - 4
c = r.Offset(0, -b).Value
d = r.Row - 10
e = r.Offset(-d, 0).Value
For Each r In Range("overviewall")
r.Formula = "=vlookup(" & a & "," & c & "_overview," & e & "+2,false)"
Next r
End Sub
Can someone point me in the right direction has how to rectify the code.
Many thanks
Sub Lookup_Formula()
Dim a$, c$, e$, f$
Dim r As Range
Set r = ActiveCell
a = r.Offset(0, -4).Value
b = r.Column - 4
c = r.Offset(0, -b).Value
d = r.Row - 10
e = r.Offset(-d, 0).Value
For Each r In Range("overviewall")
r.Formula = "=vlookup(" & a & "," & c & "_overview," & e & "+2,false)"
Next r
End Sub
Can someone point me in the right direction has how to rectify the code.
Many thanks