Copy Excel data content listed in 3 columns into a single column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My speadsheet looks like this:
Name Computer name count
Jones cpu1 5
Jones cpu2 6
Jones cpu4 15

I need for it to appear like this:
Name Computer name count
Jones cpu1,cpu2 and cpu4 26

How can this be accomplished. Thanks.
 
Try the macro below.

To use the macro:
1) Have the data sorted by the "Name" column.
2) Select any cell in your data
3) Run the macro

'-------------------------
Sub combine_rows()
Dim tmp As Single, tmp2$

tmp2 = Selection.Range("A1").CurrentRegion.Address(False, False)

With ActiveSheet.Range(tmp2).Columns(1)
If .Rows.Count >= 2 Then
For tmp = .Rows.Count To 2 Step -1
If .Rows(tmp).Value = .Rows(tmp - 1).Value Then
.Rows(tmp - 1).Offset(0, 1).Value = _
.Rows(tmp - 1).Offset(0, 1).Value & ", " & _
.Rows(tmp).Offset(0, 1).Value
.Rows(tmp - 1).Offset(0, 2).Value = _
.Rows(tmp - 1).Offset(0, 2).Value + _
.Rows(tmp).Offset(0, 2).Value
.Rows(tmp).EntireRow.Delete
End If
Next
End If
End With
End Sub
'-------------------------

Regards,
Edwin Tam
(e-mail address removed)
http://www.vonixx.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top