|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。- Sub ykcbf() '//2024.3.22
- Dim arr, brr
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Set ws = ThisWorkbook
- Set sh = ws.Sheets("汇总")
- p = ThisWorkbook.Path
- f = p & "\进货数据.xls"
- mm = "123"
- Set wb = Workbooks.Open(f, 0, False, , mm, mm)
- With wb.Sheets("Sheet1")
- arr = .UsedRange
- wb.Close False
- End With
- For i = 2 To UBound(arr)
- d1(arr(i, 2)) = arr(i, 3)
- Next
- With ws
- For Each sht In .Sheets
- If sht.Name <> sh.Name Then
- With sht
- r = .Cells(Rows.Count, 2).End(3).Row
- arr = .[a1].Resize(r, 6)
- For i = 2 To UBound(arr)
- d2(arr(i, 2)) = ""
- s = .Name & "|" & arr(i, 2)
- For j = 3 To UBound(arr, 2)
- d(s) = d(s) + arr(i, j)
- Next
- Next
- End With
- End If
- Next
- ReDim brr(1 To d1.Count, 1 To 3 + d2.Count)
- For Each k In d1.keys
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = k
- brr(m, 3) = d1(k)
- Next
- With sh
- .UsedRange.Offset(1, 3).Clear
- .[d1].Resize(1, d2.Count) = d2.keys
- .[a2].Resize(m, 3 + d2.Count) = brr
- arr = .UsedRange
- With .UsedRange
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = 2 To UBound(arr)
- For j = 4 To UBound(arr, 2)
- s = arr(i, 2) & "|" & arr(1, j)
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- .UsedRange = arr
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|