|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim mypath$, myname$
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- mypath = ThisWorkbook.Path & ""
- myname = Dir(mypath & "*.xlsx")
- Do While myname <> ""
- If myname <> ThisWorkbook.Name Then
- Set wb = GetObject(mypath & myname)
- yf = Val(myname)
- With wb
- With .Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- ReDim brr(1 To 13)
- brr(1) = arr(i, 1)
- Else
- brr = d(arr(i, 1))
- End If
- brr(yf + 1) = brr(yf + 1) + arr(i, 2)
- d(arr(i, 1)) = brr
- Next
- End With
- .Close False
- End With
- End If
- myname = Dir()
- Loop
- With Worksheets("sheet1")
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(d.Count, UBound(brr)) = Application.Transpose(Application.Transpose(d.items))
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|