OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 421
- Office Version
- 2019
- Platform
- Windows
Thanks and advance. I am getting the following error: "Run-time error '1004' "Application-definded or object defined error" on the following line:
Within Column B of Sheet1, I am checking the corresponding cell value in column C by looking it up in column A of Sheet2. If it does not find it, it tries to look up the previous cell B value, if that gives an error, it goes to input "DNE" in cell B.
VBA Code:
Range("B" & i).Formula = "= IFERROR(VLOOKUP( Range(""C""" & i & "), Sheet2!$A:$A, 1, FALSE), IFERROR(VLOOKUP(Range (""B""" & i - 1 & "), Sheet2!$A:$A, 1, FALSE), ""DNE""))"
Within Column B of Sheet1, I am checking the corresponding cell value in column C by looking it up in column A of Sheet2. If it does not find it, it tries to look up the previous cell B value, if that gives an error, it goes to input "DNE" in cell B.
VBA Code:
Option Explicit
Public Sub Frmula()
Dim i As Long
Sheets("Sheet1").Activate
For i = 8 To 3000
Range("B" & i).Formula = "= IFERROR(VLOOKUP( Range(""C""" & i & "), Sheet2!$A:$A, 1, FALSE), IFERROR(VLOOKUP(Range (""B""" & i - 1 & "), Sheet2!$A:$A, 1, FALSE), ""DNE""))"
Next i
End Sub