I have the following VLOOKUP, which is working on a Range "Sub FindReplace_With_Offset_1"
I need to run it Cell by Cell on this range with a If-Statment "Sub FindReplace_With_Offset_2"
But I can not figure out how to alter
.Value = _
"=VLOOKUP(D2," & wsFR.Range("D1").CurrentRegion.Address(1, 1, , 1) & ",2,0)"
to only run cell by cell
Thank you
Sub FindReplace_With_Offset_1()
Dim wsFR As Worksheet, wsT As Worksheet
Dim tLR As Long, i As Long
Set wsT = ThisWorkbook.Worksheets("XXX")
Set wsFR = ThisWorkbook.Worksheets("ZZZ")
With wsT
tLR = .Range("C" & .Rows.Count).End(xlUp).Row
With .Range("B2:B" & tLR) 'The Offset Range
.Value = _
"=VLOOKUP(D2," & wsFR.Range("D1").CurrentRegion.Address(1, 1, , 1) & ",2,0)"
.Value = .Value
End With
End With
End Sub
Sub FindReplace_With_Offset_2()
Dim wsFR As Worksheet, wsT As Worksheet
Dim Rng As Range, aCell As Range
Dim tLR As Long, i As Long
Set wsT = ThisWorkbook.Worksheets("XXX")
Set wsFR = ThisWorkbook.Worksheets("ZZZ")
With wsT
tLR = .Range("C" & .Rows.Count).End(xlUp).Row
With .Range("A2:A" & tLR) 'The Offset Range
Set Rng = wsT.Range("A2:A" & tLR)
For Each aCell In Rng
If aCell.text = "#N/A" Then
'I need this to run only on each aCell but it is running on the entire range every time a aCell.text = "#N/A"
.Value = _
"=VLOOKUP(D2," & wsFR.Range("D1").CurrentRegion.Address(1, 1, , 1) & ",2,0)"
.Value = .Value
Else
End If
Next aCell
End With
End With
End Sub
Bookmarks