I am trying to insert a formula into a cell with a help of VBA and all of the time I receive error 1004: "Application-defined or object-defined error". Where does the problem lie?
Worksheets("Sheet1").Range("L10").Formula = "=VLOOKUP(" & Cells(6, 15) & ", SQLTable, 2, 0)*" & Cells(6, 16)
Debug.Print "=VLOOKUP(" & Cells(6, 15) & ", SQLTable, 2, 0)*" & Cells(6, 16)and see how the result differs to the formula you would just write manually in the cell.Cellsobject (both instances) with a worksheet.Sheets("Sheet1").Cells(6, 15)etc.... or even better, create a worksheet variable for better readabilityDebug.Print "=VLOOKUP(" & Cells(6, 15) & ", SQLTable, 2, 0)*" & Cells(6, 16)and got what actually was expected=VLOOKUP(06.01.2020, SQLTable, 2, 0)*-1000. This is exactly what it would look like, if I write it manually.06.01.2020would not work in a formula like that.Worksheets("Sheet1").Selectbefore your code line