PDA

View Full Version : Solved: Combine cells values from two sheets into 1 cell



rafi_07max
12-12-2010, 04:26 AM
The code below basically inserts the value in cell A1 of sheet2 into cell A1 of sheet1.



Private Sub CommandButton1_Click()
Sheets(1).Cells(1, 1).Value = Sheets(2).Cells(1, 1).Value
End Sub

In this process before inserting the value of cell A1 of sheet2, it clears whatever content there is in cell A1 of sheet 1.


So my question is instead of clearing the content in cell A1 of sheet 1, how can I merge the value from sheet1 cell A1 and the value from sheet 2 cell A1.


For e.g. before running the macro,
sheet 1 cell A1 has a value = “apple” and
Sheet 2 cell A1 has a value of “orange”.


So once I run the macro the value cell A1 of sheet 1 should be = “apple, orange”. When merging they are separated by a comma, “,”


How can I do this?

Simon Lloyd
12-12-2010, 05:22 AM
Use this:Private Sub CommandButton1_Click()
Sheets(1).Cells(1, 1).Value = Sheets(1).Cells(1, 1).Value & ", " & Sheets(2).Cells(1, 1).Value
End Sub

rafi_07max
12-12-2010, 07:35 AM
Thanks simon for your help. It works