【发布时间】:2018-02-17 01:05:28
【问题描述】:
我需要一个显示 DriverName 和 Duration 列的表,可以删除所有其他列。必须删除所有重复项,并对每个驱动程序的持续时间求和。
我已经为此苦苦挣扎了一段时间,我一直在尝试使用的代码如下。需要在 Vba 中完成。
如果有人能提供帮助,我将不胜感激。
Sub MG02Sep59
Dim Rng As Range, Dn As Range, n As Long, nRng As Range
Set Rng = Range(Range("D2"), Range("D" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not .Exists(Dn.Value) Then
.Add Dn.Value, Dn
Else
If nRng Is Nothing Then Set nRng = _
Dn Else Set nRng = Union(nRng, Dn)
.Item(Dn.Value).Offset(, 3) = .Item(Dn.Value).Offset(, 3) + Dn.Offset(, 3)
End If
Next
If Not nRng Is Nothing Then nRng.EntireRow.Delete
End With
End Sub
【问题讨论】: