|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim d As Object
- Dim r%, i%
- Dim arr, brr
- Dim mypath$, myname$
- Dim wb As Workbook
- Set d = CreateObject("scripting.dictionary")
- mypath = ThisWorkbook.Path & ""
- myname = Dir(mypath & "2.xls")
- If myname = "" Then
- MsgBox "2.xls不存在!"
- Exit Sub
- End If
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = 0
- Next
- End With
-
- Set wb = GetObject(mypath & myname)
- With wb
- With .Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a2:b" & r)
- End With
- .Close
- End With
- For i = 1 To UBound(brr)
- For Each aa In d.Keys
- If brr(i, 1) Like "*" & aa & "*" Then
- d(aa) = d(aa) + brr(i, 2)
- End If
- Next
- Next
- For i = 1 To UBound(arr)
- arr(i, 2) = d(arr(i, 1))
- Next
- With Worksheets("sheet1")
- .Range("b2").Resize(UBound(arr), 1) = Application.Index(arr, 0, 2)
- End With
- End Sub
复制代码 |
|