|
Sub TEST()
Dim arr, vData, i&, j&, R&, dic As Object
Dim strTxt$, wks As Worksheet, vKey
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
arr = Range(Sheets("汇总").[A1], Sheets("汇总").Cells(1, Columns.Count).End(xlToLeft))
ReDim vData(1 To 10000, 1 To UBound(arr, 2)): R = R + 1
For i = 1 To UBound(arr, 2)
vData(R, i) = arr(R, i)
Next i
For Each wks In Sheets
If wks.Name Like "*-*-*" Then
With wks
If .ProtectContents = True Then .Unprotect (123)
arr = .[A7].CurrentRegion
For i = 2 To UBound(arr)
R = R + 1
For j = 1 To UBound(arr, 2)
vData(R, j) = arr(i, j)
Next j
vKey = vData(R, 3)
If Not dic.exists(vKey) Then
dic(vKey) = Array(vData(R, 9), vData(R, 10))
Else
dic(vKey) = Array(dic(vKey)(0) + vData(R, 9), dic(vKey)(1) + vData(R, 10))
End If
Next i
If .ProtectContents = False Then .Protect (123)
End With
End If
Next
Cells.Clear
[A1].Resize(R, UBound(vData, 2)) = vData
With [A1].CurrentRegion
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.Rows(1).Font.Bold = True
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
For Each vKey In dic.keys
strTxt = strTxt & vbCrLf & vKey & ":" & vbCrLf & vData(1, 9) & ":" & Format(dic(vKey)(0), "#,###.00") & vbCrLf & vData(1, 10) & ":" & Format(dic(vKey)(1), "#,###.00")
Next
strTxt = strTxt & vbCrLf & vbCrLf & "pdf文件生成在当前目录中"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\1"
Set dic = Nothing
Application.ScreenUpdating = True
Beep
MsgBox strTxt
End Sub
|
|