View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] tom_n_ape@hotmail.com is offline
external usenet poster
 
Posts: 4
Default Loop through rows to consolidate data

On Jan 7, 9:42*am, glp_127 wrote:
Thanks Tom. *Yes, I was planning to sort the data first. *And I can write a
simple IF formula to compare column A for 2 consecutive rows and when they
are equal then concatenate column B values. *But that doesn't deal with when
there are 3 or more rows to combine … or deleting the duplicate rows. *I've
written quite a few Excel formulas in my time, but am not seeing a solution
with formulas in this case. *Please let me know if you think I'm missing
something.


Alright, first sort the data alphabetically, then this code should
work for you. Let me know if you have any problems with it.

Sub findDupes()

' findDupes Macro
' Macro recorded 1/7/2009 by Tom

Dim currentRow As Integer

currentRow = 3 'or whatever row you want to start on

Do While Cells(currentRow, 1) < ""
If Cells(currentRow, 1) = Cells(currentRow + 1, 1) Then
Cells(currentRow + 1, 2).Copy
Cells(currentRow, 2) = Cells(currentRow, 2) & ", " & Cells
(currentRow + 1, 2)
'Rows((currentRow + 1) & ":" & (currentRow + 1)).Select
'use this only if you want to delete the whole row
Range(Cells(currentRow + 1, 1), Cells(currentRow + 1,
2)).Select 'use this to delete just the cells with data
Selection.Delete shift:=xlUp
Else
currentRow = currentRow + 1
End If
Loop
End Sub