|
代码如下:
- Sub ykcbf() '//2023.5.2
- Dim arr, brr, d, p, f
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim tm: tm = Timer
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- b = [{2,3,4,5,6,12,10}]
- Set sh = ThisWorkbook.Sheets("采购计划表")
- p = ThisWorkbook.Path & "" '//文件路径
- f = Dir(p & "*.xls*") '//文件名
- Do While f <> ""
- If f <> ThisWorkbook.Name Then
- fn = Split(Split(f, ".")(0), "(")(1)
- fn = Left(fn, Len(fn) - 1)
- With Workbooks.Open(p & f, 0)
- arr = .Sheets(1).UsedRange
- .Close False
- End With
- For i = 3 To UBound(arr)
- s = arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4)
- If s <> Empty Then
- If Not d.exists(s) Then
- d(s) = Array(arr(i, 2), arr(i, 3), arr(i, 4), arr(i, 5), arr(i, 6), arr(i, 12))
- End If
- d1(s & "|" & fn) = d1(s & "|" & fn) + arr(i, 10)
- End If
- Next
- End If
- f = Dir
- Loop
- On Error Resume Next
- ReDim brr(1 To d.Count, 1 To 7)
- For Each k In d.keys
- m = m + 1
- brr(m, 1) = m
- T = d(k)
- For x = 0 To d.Count - 1
- brr(m, x + 2) = T(x)
- Next
- Next
- With sh
- .UsedRange.Offset(3).ClearContents
- .[a4].Resize(m, 7) = brr
- .[a4].Resize(m, 14).Borders.LineStyle = 1
- arr = .UsedRange
- For i = 4 To UBound(arr)
- For j = 8 To 14
- s = arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4) & "|" & arr(2, j)
- If s <> Empty Then
- If d1.exists(s) Then
- arr(i, j) = d1(s)
- End If
- End If
- Next
- Next
- .UsedRange = arr
- ActiveWindow.DisplayZeros = False
- End With
- Application.ScreenUpdating = True
- MsgBox "运行完毕,共用时: " & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|