How do I concatenate cell values and text together using Excel VBA?

xxxRxxx picture xxxRxxx · Aug 17, 2015 · Viewed 58.7k times · Source

I have a repetitive task I'd like to automate instead of using the =Concatenate function all the time. Here's my code so far:

Cells(2, 5).Value = Cells(2, 1).Value&" - "&Cells(2, 2).Value

Unfortunately this results in the "Compile error: Expected: end of statement" error, which highlights the " - ". How can I sandwich that text, " - ", between those two values?

Answer

paul bica picture paul bica · Aug 17, 2015

Cells(2, 5).Value = Cells(2, 1).Value & " - " & Cells(2, 2).Value