View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Helmut Weber[_2_] Helmut Weber[_2_] is offline
external usenet poster
 
Posts: 163
Default Summing duplicate entries and non duplicates

Hi everybody,

seems, I was so exited
that I forgot about option explicit.

Just another try, using a placeholder for double entries
and deleting them later.
The first attempt was no good at all, it seems,
and I'm still fooling around with Excel.
(I'll try for x to 1 step -1).

Option Explicit
Sub Test1111()
Dim r1 As Long ' row
Dim r2 As Long ' row
Dim v As Long
Dim s1 As String
Dim s2 As String
Dim x As Long ' last row
x = Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1).Row
For r1 = 1 To x
For r2 = 1 To x
s1 = Cells(r1, 1).Value
s2 = Cells(r2, 1).Value
v = Cells(r1, 2).Value
If s1 < "---" Then
If r1 < r2 And s1 = s2 Then
v = v + Cells(r2, 2).Value
Cells(r1, 2).Value = v
Cells(r2, 1).Value = "---"
Cells(r2, 2).Value = 0
End If
End If
Next
Next
For r1 = 1 To x
While Cells(r1, 1).Value = "---"
Rows(r1).Delete
Wend
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA (not Excel, for sure)

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"