2,462
社区成员
发帖
与我相关
我的任务
分享
Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Dim m As Long
Dim lngTemp As Long
With Sheet2
m = 1
For i = 2 To Sheet1.UsedRange.Rows.Count
If Cells(i, 7) <> "Y" Then
m = m + 1
.Cells(m, 1) = Cells(i, 1)
.Cells(m, 2) = Cells(i, 2)
.Cells(m, 3) = Cells(i, 3)
.Cells(m, 4) = Cells(i, 4)
.Cells(m, 7) = Cells(i, 6)
lngTemp = 0
lngTemp = lngTemp + Cells(i, 5)
Cells(i, 7) = "Y"
For j = i + 1 To Sheet1.UsedRange.Rows.Count
If Cells(j, 7) <> "Y" Then
If Cells(i, 1) = Cells(j, 1) And Cells(i, 3) = Cells(j, 3) And Cells(i, 6) = Cells(j, 6) Then
lngTemp = lngTemp + Cells(j, 5)
Cells(j, 7) = "Y"
End If
End If
Next j
.Cells(m, 5) = lngTemp
.Cells(m, 6) = Cells(i, 4) - lngTemp
End If
Next i
End With
End Sub