|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- 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
复制代码 |
|