I have created a big formula as a string variable inside VBA. Then when I am trying to assign this formula as a value to a cell I run across the following error '1004 - Application-defined or object-defined error". Is there a way to insert my formula into a cell? Would highly appreciate any help!
Sub insertFormula()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
Dim strForm As String
Dim i As Long
ws.Range("A2").Value = "=VLOOKUP(O6; SQLTable; 2; 0)*P6"
strForm = ws.Range("A2").Value
For i = 7 To Worksheets("Sheet1").Range("O" & Rows.Count).End(xlUp).Row
strForm = strForm & "+VLOOKUP(" & ws.Cells(i, 15).Address(False, False) & "; SQLTable; 2; 0)*" & ws.Cells(i, 16).Address(False, False)
Next i
ws.Range("A2").Value = strForm
End Sub