|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
学习一下字典,打扰了
Sub test()
lastr = Cells(Rows.Count, "a").End(xlUp).Row
arr = Range("a1:b" & lastr)
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 1)) Then
d(arr(i, 1)) = arr(i, 2)
Else
If d(arr(i, 1)) < arr(i, 2) Then
d(arr(i, 1)) = arr(i, 2)
End If
End If
Next
lastr = Cells(Rows.Count, "c").End(xlUp).Row
brr = Range("c1:d" & lastr)
For i = 2 To UBound(brr)
brr(i, 2) = d(brr(i, 1))
Next
Columns(3).NumberFormat = "@"
Columns(4).NumberFormat = "yyyy-m-d"
[c1].Resize(UBound(brr), UBound(brr, 2)) = brr
End Sub |
|