|
楼主 |
发表于 2018-9-11 17:30
|
显示全部楼层
本帖最后由 财知道 于 2018-9-11 17:32 编辑
Option Explicit
Sub 导出数据()
Dim d As Object, sh As Worksheet, ar, br(), tp As Range, bm As Range, r&, c%, k&, y&, st$
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each sh In Worksheets
Next
Application.DisplayAlerts = True
Set d = CreateObject("scripting.dictionary")
With Worksheets("查询表")
ar = .[a1].CurrentRegion
Set tp = .[a1].CurrentRegion.Resize(3)
Set bm = .[a65536].End(3).Resize(1, UBound(ar, 2))
End With
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For r = 4 To UBound(ar) - 1
st = ""
For c = 1 To UBound(ar, 2)
If c <> 11 Then st = st & ar(r, c)
Next
If Not d.exists(st) Then
k = k + 1
d(st) = k
For c = 1 To UBound(ar, 2)
br(k, c) = ar(r, c)
Next
Else
y = d(st)
br(y, 11) = br(y, 11) + ar(r, 11)
End If
Next
If k Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
With ActiveSheet
.Name = "导出数据"
tp.Copy .[a1]
With .[a4].Resize(k, UBound(br, 2))
.Value = br
.Borders.LineStyle = 1
' .HorizontalAlignment = xlCenter
End With
bm.Copy .[a65536].End(3)(2)
.[e4].Resize(k).NumberFormatLocal = "00"
.[j4].Resize(k).NumberFormatLocal = "0000"
.[a:r].EntireColumn.AutoFit
.DrawingObjects.Delete
End With
End If
Worksheets("查询表").Activate
Set d = Nothing: Set tp = Nothing: Set bm = Nothing
Application.ScreenUpdating = True
End Sub
求这个代码的解释,本人套用到别处相同记录不会汇总了~~~
|
|