|
Sub 按钮1_Click()
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
arr = Sheets("主表").UsedRange
For j = 3 To UBound(arr)
If Len(arr(j, 1)) > 0 Then
For i = 5 To UBound(arr, 2)
If Len(arr(j, i)) > 0 Then
If Not d.exists(arr(j, i)) Then
Set d(arr(j, i)) = CreateObject("scripting.dictionary")
End If
Set d(arr(j, i))(arr(j, 1)) = Sheets("主表").Cells(j, 2).Resize(1, 3)
End If
Next i
End If
Next j
With Sheets("子表")
.UsedRange.Clear
r = 1
For Each k In d.keys
.Cells(r, 1) = "数据统计"
.Cells(r, 2).Resize(1, 3).Merge
.Cells(r, 2) = k
For Each kk In d(k).keys
r = r + 1
.Cells(r, 1) = kk
.Cells(r, 2).Resize(1, 3).Value = d(k)(kk).Value
Next kk
r = r + 3
Next k
.UsedRange.HorizontalAlignment = xlCenter
.UsedRange.VerticalAlignment = xlCenter
.UsedRange.Borders.LineStyle = xlContinuous
End With
Application.ScreenUpdating = True
End Sub
|
|