|
来看看如何- Sub Main()
- Dim Dic As Object, Krr, Trr
- Dim Arr
- Dim i As Integer, MaxRow1 As Integer, MaxRow2 As Integer
- Set Dic = CreateObject("Scripting.Dictionary")
- MaxRow1 = Sheets("sheet1").Cells(1048576, 1).End(xlUp).Row
- MaxRow2 = Sheets("sheet2").Cells(1048576, 1).End(xlUp).Row
- If Sheets("sheet1").Cells(1, 1).Value = "" Then Exit Sub
- ReDim Arr(1 To MaxRow1)
- If Sheets("sheet2").Cells(1, 1).Value <> "" Then
- For i = 1 To MaxRow2
- Dic(Sheets("sheet2").Cells(i, 1).Value) = Sheets("sheet2").Cells(i, 2).Value
- Next
- End If
- For i = 1 To MaxRow1
- Dic(Sheets("sheet1").Cells(i, 1).Value) = Dic(Sheets("sheet1").Cells(i, 1).Value) + 1
- Next
- Krr = Dic.keys
- Trr = Dic.items
- For i = 0 To Dic.Count - 1
- Sheets("sheet2").Cells(i + 1, 1) = Krr(i)
- Sheets("sheet2").Cells(i + 1, 2) = Trr(i)
- Next
- End Sub
复制代码
|
|