I have a variable a = "C2" and variable b = "C3"
I need to do something like
ws.Range("A2").Value = "=" & a &"" ""& b
which should return:
=C2&" "&C3
in an excel formula however I cant seem to get this to work anyone have a solution??
From my comment,
ws.Range("A2").Formula = "=" & a & "&"" ""&" & b
This works because you need to use .Formula instead of .Value.
.Value just the same. If someone can comment as to why, that'd be appreciated! Perhaps it's because you're using an = at the start, so of course, when Excel sees an = at the start, it uses it as a formula. I wonder then, what the "real" big difference in using .Value and .Formula for setting formulas is.
=C2&" "&C3, or do you want it to show the values of C2 and C3, separated by a space? Tryws.Range("A2").Formula = "=" & a & "&"" ""&" & b. If you want the values of your variables, separated by a space, usews.Range("A2").Value = a & " " & b.