|
Sub test()
'定义数组和字典
Dim brr(2)
Set dic = CreateObject("scripting.dictionary")
With Worksheets("sheet1")
'名称去重并加入字典
arr = .[a7].CurrentRegion.Value
For irow = 2 To UBound(arr, 1)
name_ = arr(irow, 2)
If Not dic.exists(name_) And Not IsEmpty(name_) Then
dic(name_) = brr
End If
Next
'经过从上到下对比,符合要求的替换名称中的数组。所以sheet1的时间排列应该从上到下逐渐递增。
For irow = 2 To UBound(arr, 1) - 1
name_ = arr(irow, 2)
If dic.exists(name_) And dic(name_)(2) <= arr(irow, 3) Then
crr = Array(arr(irow, 1), name_, arr(irow, 3))
dic(name_) = crr
End If
Next
End With
'打印
With Worksheets("sheet2")
.[a:c].Clear
.[a1].Resize(1, 3) = Array("时间", "名称", "value")
irow = 2
For Each k In dic.Keys
.Cells(irow, 1).Resize(1, 3) = dic(k)
irow = irow + 1
Next
End With
End Sub
|
|