|
数据更新。。。。- Sub ykcbf() '//2024.8.19
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set sh = ThisWorkbook.Sheets("清单总表")
- With sh
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .Cells(1, "XFD").End(1).Column
- arr = .[a1].Resize(r, c)
- End With
- ReDim brr(1 To 10000, 1 To 100)
- n = 4
- For i = 1 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- For j = 1 To UBound(arr, 2)
- brr(m, j) = arr(i, j)
- Next
- End If
- r = d(arr(i, 1))
- For j = 5 To UBound(arr, 2)
- s = CStr(arr(1, j))
- If Not d.exists(s) Then
- n = n + 1
- d(s) = n
- End If
- Next
- Next
- With Application.FileDialog(msoFileDialogFilePicker)
- .InitialFileName = ThisWorkbook.Path & ""
- .Title = "请选择对应Excel文件"
- .AllowMultiSelect = False
- .Filters.Clear
- .Filters.Add "Excel文件", "*.xls*"
- If .Show Then f = .SelectedItems(1) Else Exit Sub
- End With
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets("Sheet2")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 4)
- End With
- wb.Close 0
- On Error Resume Next
- If Not d.exists(fn) Then
- n = n + 1
- d(fn) = n
- brr(1, n) = fn
- End If
- c = d(fn)
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = arr(i, 2)
- brr(m, 3) = arr(i, 4)
- brr(m, c) = arr(i, 3)
- End If
- r = d(arr(i, 1))
- brr(r, c) = arr(i, 3)
- Next
- With sh
- .UsedRange.Clear
- .[a1].Resize(1, n).Interior.Color = 49407
- With .[a1].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = 2 To m
- .Cells(i, 4) = Application.Sum(.Cells(i, 5).Resize(, c - 4))
- Next
- End With
- Set d = Nothing
- Application.ScreenUpdating = False
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|