I'm trying to add a formula to a cell that combines text from a cell in the Excel worksheet and different strings that are created in my VBA code. The formula that I need is rather long so I broke it down to the most simple version to understand what I'm doing wrong. I looked for similar examples online but I just can't get it right.
When the string comprises of only numbers or when I replace the string by an integer, the formula works, but when I use a "real" string, it puts @ in front of the string. When I use .formula2
, the @ disappears but I still don't get what I need. Can someone point me in the right direction?
Dim xCode As String
xCode = "123"
Range("S4").Formula = "=R4 & " & xCode
Dim xCode As String
xCode = "ABC"
Range("S4").Formula = "=R4 & " & xCode
Dim xCode As String
xCode = "ABC"
Range("S4").Formula2 = "=R4 & " & xCode