Excel 在通过切片器更改数据透视表之前运行代码
我甚至不确定这是否可能 因此,我有下面的Excel 在通过切片器更改数据透视表之前运行代码,excel,vba,pivot-table,Excel,Vba,Pivot Table,我甚至不确定这是否可能 因此,我有下面的工作表\u Change和工作表Calculate,每当我在创建的切片器中选择透视表过滤器项时,它都会格式化我的工作表(如果需要,隐藏行和格式化日期)。现在,我希望添加的另一个功能是在数据透视表区域旁边的相邻列中添加一个“Comments”列。这些“注释”将被复制并作为值粘贴到另一张图纸上,以及轴的数据。同样,数据透视表也只能作为值进行复制和粘贴 通常情况下,当在切片器中选择过滤器项时,数据透视表区域的列数将发生变化,因为值字段是动态的。因此,它可能是一个
工作表\u Change
和工作表Calculate
,每当我在创建的切片器中选择透视表过滤器项时,它都会格式化我的工作表(如果需要,隐藏行和格式化日期)。现在,我希望添加的另一个功能是在数据透视表区域旁边的相邻列中添加一个“Comments”列。这些“注释”将被复制并作为值粘贴到另一张图纸上,以及轴的数据。同样,数据透视表也只能作为值进行复制和粘贴
通常情况下,当在切片器中选择过滤器项时,数据透视表区域的列数将发生变化,因为值字段是动态的。因此,它可能是一个过滤器项上的一列,另一个过滤器项上的八列。这意味着我不能将“Comments”列放在透视表右侧的最后一列旁边,因为它可能会被新的筛选报告覆盖。所以,是的,在覆盖发生之前,我希望先将注释列复制到另一个工作表中
任何帮助都将不胜感激。提前谢谢
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("b1:p7")) Is Nothing Then
'Unhide all rows first
Range("A4").Select
ActiveCell.Offset(0, 0).Range("A1:A1000").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Hidden = False
'Hide rows outside Pivot Table report area
Range("A7").Select
Selection.End(xlDown).Select
ActiveCell.Offset(3, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Hidden = True
Range("A800").Select 'above project no.
Selection.End(xlDown).Select
ActiveCell.Offset(3, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Hidden = True
'format date
If Range("G7") = "End dates Due" Then
Range("G7").Select
ActiveCell.Range("A1:A792").Select
Selection.NumberFormat = "m/d/yyyy"
Else
Range("G7").Select
ActiveCell.Range("A1:A792").Select
Selection.NumberFormat = "#,##0.00"
End If
End If
End Sub
Private Sub Worksheet_Calculate()
If Me.Range("A802").Value = "" Then 'below project no.
Me.Range("A796:A801").EntireRow.Hidden = True 'from proj manager to project no.
Else
Me.Range("A796:A801").EntireRow.Hidden = False
End If
If Me.Range("A823").Value = "" Then 'below project no.
Me.Range("A817:A822").EntireRow.Hidden = True
Else
Me.Range("A817:A822").EntireRow.Hidden = False
End If
If Me.Range("A802").Value = "" And _
Me.Range("A823").Value = "" Then
Me.Range("A794:A822").EntireRow.Hidden = True 'from report no. to 2nd proj. no.
End If
End Sub
为什么不把
注释
放在数据透视表的左侧呢?我希望它能像在填写表中一样更有效,人们通常会在他们所指的数据的右侧添加注释,而不是在数据透视表更新之前复制注释,而是在输入注释后复制注释。这样,注释将提前到达目的地,并且信息将并发。使用工作表\u数据透视表更新
事件为注释创建范围,使用工作表\u更改
事件验证注释并将其移动到目的地。