|
Private Sub CommandButton1_Click()
Dim tim1 As Date, tim2 As Date: tim1 = Timer
Dim arr, d As Object, sht As Worksheet
Set d = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
For i = 1 To UBound(arr)
If Not d.exists(arr(i, 1)) Then
Set d(arr(i, 1)) = Range("a" & i).Resize(1, 94)
Else
Set d(arr(i, 1)) = Union(d(arr(i, 1)), Range("a" & i).Resize(1, 94))
End If
Next
x = d.keys
For k = 1 To UBound(x)
Set sht = ActiveWorkbook.Sheets.Add(, after:=ActiveSheet)
sht.Name = x(k)
d.items()(k).Copy sht.Range("a" & 2)
Rows("1:1").Copy sht.[a1]
Next
For Each sht In Sheets
If sht.Name <> "Sheet1" Then
With sht
k = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .[a1].CurrentRegion
For i = 2 To UBound(arr)
For j = 6 To UBound(arr, 2)
If IsNumeric(.Cells(i, j)) Then
.Cells(k + 1, j) = Application.Average(Application.Index(arr, , j))
End If
Next
Next
End With
End If
Next
tim2 = Timer
MsgBox Format(tim2 - tim1, "拆分完成,共耗时:0.00秒"), 64, "时间统计"
End Sub |
|