|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim mypath$, myname$
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- mypath = ThisWorkbook.Path & ""
- myname = "操作表.xlsx"
- If Dir(mypath & myname) = "" Then
- MsgBox mypath & myname & "不存在!"
- Exit Sub
- End If
- Set wb = GetObject(mypath & myname)
- With wb
- With .Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- End With
- .Close False
- End With
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = arr(i, 2)
- Next
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2:a" & r)
- ReDim brr(1 To UBound(arr), 1 To 1)
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 1)) Then
- brr(i, 1) = d(arr(i, 1))
- End If
- Next
- .Cells(2, c + 1).Resize(UBound(brr), UBound(brr, 2)) = brr
- .Range("a2").Resize(r - 1, c + 1).Sort key1:=.Cells(2, c + 1), order1:=xlAscending, Header:=xlNo
- End With
- Application.ScreenUpdating = True
- MsgBox "数据匹配完毕!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|