|
楼主 |
发表于 2015-1-27 00:01
|
显示全部楼层
我又参考了9楼老师的代码,加入了按A列排序的代码,太好了!- Sub 添加()
- Dim Arr, Brr, drow%, i%, j%, d, Crr(), k%
- k = 1
- Set d = CreateObject("scripting.dictionary")
- Arr = Worksheets("添加").Range("a2:b" & Worksheets("添加").Range("a65536").End(3).Row)
- With Worksheets("明细")
- drow = .Range("a65536").End(3).Row
- Brr = .Range("a2:b" & drow)
- For i = 1 To UBound(Brr)
- d(Brr(i, 1)) = Brr(i, 2)
- Next
- ReDim Crr(1 To UBound(Arr), 1 To 2)
- For i = 1 To UBound(Arr)
- If Not d.exists(Arr(i, 1)) Then
- Crr(k, 1) = Arr(i, 1): Crr(k, 2) = Arr(i, 2)
- k = k + 1
- End If
- Next
- .Range("a" & drow + 1).Resize(k, 2) = Crr
- .Columns("A:B").Sort Key1:=.Range("A1"), Order1:=xlAscending, Header:=xlYes
- End With
- End Sub
复制代码 |
|