|
- Sub 汇总()
- Set d = CreateObject("scripting.dictionary")
- ph = ThisWorkbook.Path & ""
- nm = Split(ThisWorkbook.Name, ".")(0)
- f = Dir(ph & "*.xls")
- Application.ScreenUpdating = False
- Do While f <> ""
- If InStr(f, nm) = 0 Then
- With Workbooks.Open(ph & f, 0)
- arr = .Sheets(1).UsedRange
- .Close False
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 15)
- If Len(s) <> 0 Then
- sl = arr(i, 22)
- If InStr(sl, ".") Then sl = Replace(arr(i, 22), ".", "") * 1
- If d.exists(s) Then
- d(s) = d(s) + sl
- Else
- d(s) = sl
- End If
- End If
- Next i
-
- With Sheets(1)
- lc = .Cells(2, Columns.Count).End(xlToLeft).Column
- If lc > 1 Then lc = lc + 1
- .Cells(1, lc) = Split(f, ".")(0)
- .Cells(2, lc) = "规格": .Cells(2, lc + 1) = "数量"
- .Cells(3, lc).Resize(d.Count) = Application.Transpose(d.keys)
- .Cells(3, lc + 1).Resize(d.Count) = Application.Transpose(d.items)
- End With
- d.RemoveAll
- End If
- f = Dir
- Loop
- Application.ScreenUpdating = True
- Set d = Nothing
- MsgBox "运行完毕!"
- End Sub
复制代码 |
|