我有一个用户表单,用户可以在其中生成每周报告。
现在我需要计算并在此报告中显示(红色突出显示区域),以及与上周和上个月的差异。
我的代码如下;
If lboCharts.Value = "Ranking Changes in A-Bucket" And cboType.Value = "Regions" Then
Sheets("Report").Select
If lblCounter.Caption = "" Then
deleteReportSheet
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"RAW!R1C1:R1048576C20", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Report!R1C1", TableName:="regions_ranking_changes_in_a_bucket", DefaultVersion _
:=xlPivotTableVersion14
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Month")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Pagetype")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Pagetype").ClearAllFilters
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Pagetype").CurrentPage = _
"Region"
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Bucket")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Bucket").ClearAllFilters
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Bucket").CurrentPage = "A"
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Date")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Theme")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Keyword")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").AddDataField ActiveSheet.PivotTables( _
"regions_ranking_changes_in_a_bucket").PivotFields("Position"), "Count of Position", xlCount
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Count of Position")
.Caption = "Average of Position"
.Function = xlAverage
End With
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Domain")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket")
.ColumnGrand = False
.RowGrand = False
End With
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Domain").ClearAllFilters
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Domain").CurrentPage = Trim(cboCountry.Value)
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Date").PivotFilters.Add _
Type:=xlAfterOrEqualTo, Value1:=Trim(tbDate.Value)
lblCounter.Caption = "1"
btnGenerateReport.Caption = "Update Report"
Else
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Domain").ClearAllFilters
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Domain").CurrentPage = Trim(cboCountry.Value)
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Date").ClearAllFilters
ActiveSheet.PivotTables("regions_ranking_changes_in_a_bucket").PivotFields("Date").PivotFilters.Add _
Type:=xlAfterOrEqualTo, Value1:=Trim(tbDate.Value)
End If
End If
我的报告应该是这样的;
PS:列顺序不稳定。
我会很感激你的帮助。
先感谢您。