Concatenate 2 cells from Sheet1 to 1 cell Sheet2

1

EDIT: Found the stray code that threw it off. Thanks everyone!

I've been trying to figure out the code to concatenate

Worksheets("Sheet1").Range ("B2:C2")

to this reference cell with " - " character as a separator:

Worksheets("Sheet2").Range ("B2")

I've tried the following, but it says "subscript out of range":

Worksheets("Sheet2").Range("B2").Cell.Value = 
  Worksheets("Sheet1").Range("B2").Cell.Value & 
    Worksheets("Sheet1").Range("C2").Cell.Value

I've also tried this, but it only copies Sheet1.C2 to Sheet2.C2:

Set sourceRange = Worksheets("Sheet1").Range("B2:C2")
Set targetRange = Worksheets("Sheet2").Range("B2")

sourceRange.Copy
targetRange.PasteSpecial Paste:=xlPasteValues

Any help on this would be appreciated. Thanks in advance!

Tmcc

Posted 2017-03-24T18:07:19.673

Reputation: 13

Answers

1

You've extra cells

Worksheets("Sheet2").Range("B2").Value = Worksheets("Sheet1").Range("B2").Value & Worksheets("Sheet1").Range("C2").Value

Should work.

Máté Juhász

Posted 2017-03-24T18:07:19.673

Reputation: 16 807

I see no difference between what the author tried and your suggestion. I could also be blind. It would make sense, I attempted to ssh into the same host, I was phyiscally at just a little awhile ago. – Ramhound – 2017-03-24T18:32:54.270

1("B2").Cell.Value vs ("B2").Value (no "CELL" in Máté suggestion) – arana – 2017-03-24T18:38:58.100