View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Excel Hates Me Excel Hates Me is offline
external usenet poster
 
Posts: 11
Default Combine/Merge Rows, Multiple Worksheets

I found this from a solution Dave Peterson provided in 2006 to delete
duplicate rows based on a match in columns 1-4; how could I add code
to have it sum the values in columns Q:AA and AC:AV as well?

Option Explicit
Sub FixDuplicateRows()
Dim RowNdx As Long
Dim iCol As Long
Dim DeleteThisRow As Boolean
Dim rng As Range


For RowNdx = Selection(Selection.Cells.Count).Row To _
Selection(1).Row + 1 Step -1


DeleteThisRow = True
For iCol = 1 To 4 'column A to column D
If Cells(RowNdx, iCol).Value = Cells(RowNdx - 1,
iCol).Value Then
'do nothing, keep looking for a difference
Else
DeleteThisRow = False
Exit For
End If
Next iCol


If DeleteThisRow = True Then
If rng Is Nothing Then
Set rng = Cells(RowNdx, 1)
Else
Set rng = Union(rng, Cells(RowNdx, 1))
End If
End If
Next RowNdx
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub