Using this SO answer, i've been trying to get the following code to work.
' inserting formulas into the userOutput.csv sheet
Dim wsUser As Worksheet: Set wsUser = Worksheets("userOutput.csv")
Dim agentEmailRange As Range: 'Set agentEmailRange = wsUser.Range(Cells(2, agentEmailColumn), Cells(propertyRows, agentEmailColumn))
' following line fails with runtime error 1004, method 'range' of object '_Worksheet' fialed.
Set agentEmailRange = wsUser.Range(Cells(2, agentEmailColumn), Cells(propertyRows, agentEmailColumn))
wsUser.Range("I1") = "Agent Email"
With agentEmailRange
.Value = "VLOOKUP(RC[-1], 'agentsOutput.csv'!R2C1:R" & agentRows & "C6 ,4, FALSE)"
End With
the odd thing is it works one time. When I change one of the variables, however, it begins to fail.
How do I get that formula in the cells I need on a dynamic basis?