|
参与一下。。。
- Sub ykcbf() '//2024.7.9 多表排重汇总,分表字段名位置不固定
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("数据汇总表")
- ReDim brr(1 To 10000, 1 To 6)
- With sh
- For j = 1 To 6
- s = .Cells(1, j)
- d1(s) = j
- Next
- End With
- On Error Resume Next
- For Each sht In ThisWorkbook.Sheets
- If sht.Name <> sh.Name Then
- With sht
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- fn = .Name
- End With
- ReDim zrr(1 To 5)
- For x = 1 To 5
- For j = 1 To UBound(arr, 2)
- If d1(arr(1, j)) = x Then
- zrr(x) = j
- Exit For
- End If
- Next
- Next
- For i = 2 To UBound(arr)
- s = arr(i, zrr(1)) & "|" & arr(i, zrr(2)) & "|" & arr(i, zrr(3))
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 6) = fn
- For k = 1 To 5
- brr(m, k) = arr(i, zrr(k))
- Next
- Else
- r = d(s)
- brr(r, 4) = brr(r, 4) + arr(i, zrr(4))
- brr(r, 5) = brr(r, 5) + arr(i, zrr(5))
- End If
- Next
- End If
- Next
- With sh
- .UsedRange.Offset(1).Clear
- With .[a2].Resize(m, 6)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|