Sub otchet Dim ws As Worksheet Dim wb As Workbook Dim ab As Workbook S

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Sub otchet()
Dim ws As Worksheet
Dim wb As Workbook
Dim ab As Workbook
Set ab = ActiveWorkbook
Dim newSh As Worksheet
If Dir("D:\Отчет Кац") <> "" Then
Kill "D:\Отчет Кац"
End If
Set wb = Workbooks.Add
wb.SaveAs Filename:="D:\Отчет Кац.xls"
wb.Sheets(1).Columns.ColumnWidth = 15
LastRow = wb.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
For Each ws In ab.Worksheets
ws.Range("A2:A25").Copy Destination:=wb.Sheets(1).Range("A" & LastRow + 1)
Dim temp As String
LastRow = wb.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
Next ws
wb.Sheets(1).Range("A2:A" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("B2"), Unique:=True
wb.Sheets(1).Range("A2:A150").Clear
wb.Sheets(1).Range("B2:B" & LastRow).Copy Destination:=Range("A2:A" & LastRow)
wb.Sheets(1).Range("B2:B" & LastRow).Clear
ab.Worksheets("январь").Range("A1").Copy Destination:=wb.Sheets(1).Range("A1")
ab.Worksheets("январь").Range("B1").Copy Destination:=wb.Sheets(1).Range("H1")
wb.Sheets(1).Cells(24, 1).Delete
wb.Sheets(1).Range("A2:A27").Sort Key1:=Range("A2"), Order1:=xlAscending
summa = 0
For i = 2 To 27
For Each ws In ab.Worksheets
a = ws.Name
t = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
summa = summa + WorksheetFunction.SumIf(ws.Range("A2:B" & t), wb.Sheets(1).Range("A" & i), ws.Range("B2:B" & t))
wb.Sheets(1).Cells(i, ws.Index + 1) = WorksheetFunction.SumIf(ws.Range("A2:B" & t), wb.Sheets(1).Range("A" & i), ws.Range("B2:B" & t))
Next ws
wb.Sheets(1).Cells(i, 8) = summa
summa = 0
Next i
For Each ws In ab.Worksheets
wb.Sheets(1).Cells(1, ws.Index + 1) = ws.Name
wb.Sheets(1).Cells(1, ws.Index + 1).Interior.Color = ab.Sheets(1).Cells(1, 1).Interior.Color
Next ws
wb.Save
End Sub