Вот мой код:
Private Sub Worksheet_Activate()
'Declarations.
Dim WksReport As Worksheet
Dim WksData As Worksheet
Dim RngDataFirstCell As Range
Dim RngReportFirstCell As Range
Dim RngRange01 As Range
Dim RngTarget As Range
Dim IntCounter01 As Integer
Dim StrTotalLabel As String
'Setting variables.
Set WksReport = Sheets(Me.Name) 'put here the sheet where the report will be contained (no need to edit if it remain a worksheet_activate sub)
Set WksData = Sheets("Foglio7") 'put here the sheet where the data will be contained
Set RngDataFirstCell = WksData.Range("A2") 'put here the first top left cell of the data table (according to your screenshot it's A2)
Set RngReportFirstCell = WksReport.Range("B2") 'put here the first top left cell of the report table
StrTotalLabel = "Gesamt" 'put here the label used for columns with totals
'Asking permission to update the report. If denied, the sub is terminated.
If MsgBox("Update the report?", vbYesNo, "Report update") = 7 Then
Exit Sub
End If
'Checking for pre-existing report.
If RngReportFirstCell.Value <> "" Then
'Setting RngTarget.
Set RngTarget = WksReport.Range(RngReportFirstCell, WksReport.Cells(RngReportFirstCell.Offset(0, 1).End(xlDown).Row, RngReportFirstCell.Offset(0, 3).column))
'Clearing RngTarget.
RngTarget.ClearContents
RngTarget.ClearFormats
End If
'Typing in the report's label.
RngReportFirstCell.Value = "Person" 'Person
RngReportFirstCell.Offset(0, 1).Value = "Project" 'Project
RngReportFirstCell.Offset(0, 2).Value = "Monat" 'Month
RngReportFirstCell.Offset(0, 3).Value = "Arbeitsstunde" 'Working hour
'Setting RngRange01 to cover the data without any row/column tag.
Set RngTarget = RngDataFirstCell.EntireRow.Find("", RngDataFirstCell, xlValues, xlWhole, xlByColumns, xlNext, False, , False).Offset(2, -1)
Set RngRange01 = RngDataFirstCell.EntireColumn.Find("", RngDataFirstCell.Offset(2, 0), xlValues, xlWhole, xlByRows, xlNext, False, , False).Offset(-1, 1)
Set RngRange01 = WksData.Range(RngTarget, RngRange01)
'Covering each cell in RngRange01.
IntCounter01 = 1
For Each RngTarget In RngRange01
'Checking if the column is not labeled for totals.
If WksData.Cells(RngDataFirstCell.Row + 1, RngTarget.column) <> StrTotalLabel Then
'Report the person.
RngReportFirstCell.Offset(IntCounter01, 0).Value = WksData.Cells(RngDataFirstCell.Row + 1, RngTarget.column)
'Report the project.
RngReportFirstCell.Offset(IntCounter01, 1).Value = WksData.Cells(RngDataFirstCell.Row, RngTarget.column)
'Report the month.
RngReportFirstCell.Offset(IntCounter01, 2).Value = WksData.Cells(RngTarget.Row, RngDataFirstCell.column)
'Report the working hour.
RngReportFirstCell.Offset(IntCounter01, 3).Value = RngTarget.Value
'Setting IntCounter01 for the next row.
IntCounter01 = IntCounter01 + 1
End If
Next
End Sub
Он разработан как частная подпрограмма Worksheet_Activate, поэтому он должен быть помещен в модуль листа отчета. Он в основном охватывает каждую ячейку ваших данных, если между месяцами или проектами нет промежутков. Затем он сообщает значение ячейки в строке с соответствующим лицом, проектом и месяцем. Он уже игнорирует ваши итоги (Gesamt). Таким образом, вы должны легко применить сводную таблицу на нем. Скажите, работает ли он, и если вам нужны какие-либо разъяснения, а также изменения / улучшения.