|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。
- Sub ykcbf() '//2024.4.2
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set sh = ThisWorkbook.Sheets("汇总")
- p = ThisWorkbook.Path & ""
- bt = 1: m = 0
- On Error Resume Next
- ReDim brr(1 To 10000, 1 To 100)
- For Each f In fso.GetFolder(p).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- arr = wb.Sheets(1).UsedRange
- wb.Close False
- For i = bt + 1 To UBound(arr)
- s = CStr(arr(i, 2))
- If Val(s) Then
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- For j = 2 To UBound(arr, 2)
- brr(m, j - 1) = brr(m, j - 1) + arr(i, j)
- Next
- Else
- r = d(s)
- For j = 4 To UBound(arr, 2)
- brr(r, j - 1) = brr(r, j - 1) + arr(i, j)
- Next
- End If
- End If
- Next
- End If
- End If
- Next f
- With sh
- .UsedRange.Offset(1).Clear
- .[a1].Resize(1, UBound(arr, 2) - 1).Interior.Color = 49407
- .Columns(1).NumberFormatLocal = "@"
- With .[a2].Resize(m, UBound(arr, 2) - 1)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter '//列居中
- .VerticalAlignment = xlCenter
- End With
- .[a2].Resize(m, UBound(arr, 2) - 1).Sort .[a2], 1
- ActiveWindow.DisplayZeros = False
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|