I am trying to add cell formulas using VBA. When the code runs I get a 'Run Time Error 1004' application defined or object defined error. The error occurs where it is inserting the formulas into the cell. I have commented out the first one or two and still get the error. These formulas work when entered in the spreadsheet. The code I am using is below
'CORRECTS THE NO FLEET ID OR LTR ISSUE
Sheets("RPT 5").Select
If Range("G5") <> "" Then
Columns("E:E").Insert
Sheets("Data").Select
'CLEAR FORMULAS TO INSERT NEW
Range("D4:H504").Select
Selection.ClearContents
Range("D4").Formula = "=IF('RPT 5'!G6>0,('RPT 5'!G6),(""))"
Range("E4").Formula = "=IFERROR(IF(INDEX('MAKE MODEL'!B:G,MATCH(D4,'MAKE MODEL'!B:B,0),6)=0,(""),(INDEX('MAKE MODEL'!B:G,MATCH(D4,'MAKE MODEL'!B:B,0),6))),"")"
Range("F4").Formula = "=IF(D4="",(""),('RPT 5'!A6))"
Range("G4").Formula = "=IF(D4="",(""),('RPT 5'!B6))"
Range("H4").Formula = "=IF(D4="",(""),('RPT 5'!C6))"
End If
Bookmarks