|
Private Sub CommandButton1_Click()
Dim arr, brr(1 To 100000, 1 To 3), i&, j&, m&, l&, t, d As Object, x$, rng As Range
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
Range("A2:e2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
With Me.ListView1
For l = 1 To .ListItems.Count
If .ListItems(l).Checked = True Then
arr = Sheets("" & .ListItems(l).Text).[b1].CurrentRegion
For i = 2 To UBound(arr)
x = arr(i, 1) & arr(i, 2)
t = d(x)
If t = "" Then
m = m + 1
d(x) = m
brr(m, 1) = x
brr(m, 2) = arr(i, 10)
brr(m, 3) = arr(i, 11)
Else
brr(t, 2) = brr(t, 2) + arr(i, 10)
brr(t, 3) = brr(t, 3) + arr(i, 11)
End If
Next
End If
Next
End With
If m = 0 Then MsgBox "不能一个表格都不选择!请选择表格。": Exit Sub
Range("A2").Resize(m, 3) = brr
drr = [a1].CurrentRegion
[a2].Resize(UBound(drr) - 1, 3).Sort [a2], 1
Range("a2:c" & UBound(drr)).Sort Key1:=Range("a2"), Order1:=xlAscending
For h = 2 To UBound(drr)
Cells(h, 4) = Left(Cells(h, 1), 4)
If Not Cells(h, 1).Find("[", , , 2) Is Nothing Then
Cells(h, 5) = Cells(h, 4) & Application.Text(Application.CountIf _
(Range(Cells(2, 4), Cells(h, 4)), Cells(h, 4)), "00")
Else
Cells(h, 5) = Cells(h, 4) & "00"
End If
Next
[a2].Resize(UBound(drr) - 1, 5).Sort [e2], 1
[D:E] = ""
Columns("A:A").Select
With Selection.Font
.ColorIndex = xlAutomatic
'.TintAndShade = 0
End With
For Each rng In [a1].CurrentRegion
If Not rng.Find("[", , , 2) Is Nothing Then
With rng.Characters(Start:=1, Length:=4).Font
.ColorIndex = 2
'.ThemeColor = xlThemeColorDark1
End With
End If
Next
Range("A1").Select
Application.ScreenUpdating = True
Unload Me
End Sub
|
|