reformatting a table

  • Thread starter Thread starter firstfoot
  • Start date Start date
F

firstfoot

Here is one way

Sub CDCollection()
Dim cLastRow As Long
Dim rng As Range
Dim i As Long

Columns("A:A").Cut
Range("C1").Insert Shift:=xlToRight
cLastRow = Cells(Rows.Count, "A").End(xlUp).row
For i = cLastRow To 2 Step -1
If Cells(i, "A").Value = Cells(i - 1, "A").Value Then
Cells(i, "A").Offset(0, 1).Resize(1, 20).Copy _
Destination:=Cells(i - 1, "C")
If rng Is Nothing Then
Set rng = Cells(i, "A")
Else
Set rng = Union(rng, Cells(i, "A"))
End If
End If
Next i

If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
Range("A1").Select

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Bob

Many thanks for that.

It worked a treat and has saved me from inflicting more pain on m
already severely bruised head:
 

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