Reputation: 175
I'm trying to merge the content of some cells into one, but each piece of information in one line within the cell. Does anyone know how to do it with VBA? I attach a picture to help explain it.
Upvotes: 0
Views: 198
Reputation: 4378
This piece of code should do the trick:
Sub MergeContents()
Dim i As Integer
For i = 2 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row Step 1
ActiveSheet.Cells(i, 9).Value = _
ActiveSheet.Cells(1, 1).Value & ": " & ActiveSheet.Cells(i, 1).Value & Chr(10) & _
ActiveSheet.Cells(1, 2).Value & ": " & ActiveSheet.Cells(i, 2).Value & Chr(10) & _
ActiveSheet.Cells(1, 3).Value & ": " & ActiveSheet.Cells(i, 3).Value & Chr(10) & _
ActiveSheet.Cells(1, 4).Value & ": " & ActiveSheet.Cells(i, 4).Value
Next i
End Sub
Upvotes: 1