希望得到一些指导。每次在excel切片器中选择新选择时,我想在工作表中运行现有代码。我是新手代码,所以如果有人回复,请具体说明我放置代码的位置。见下文。代码的最后一部分是我尝试运行代码,如果进行了新的选择,但它不起作用并返回错误。
Sub ConditionalFormatting()
End Sub
Set a = Sheets("Pivot")
i = 6 'row
j = 6 'column
Do Until a.Cells(4, j) = "Grand Total" 'tells code to continue the code until it finds Grand Total
j = j + 1
Loop
j = j - 1
vArr = Split(Cells(1, j).Address(True, False), "$")
a.Cells(1, 15) = vArr
Do Until a.Cells(i, 5) = ""
a.Range("F" & i & ":" & a.Cells(1, 15).Value & i).Select
Selection.FormatConditions.AddColorScale ColorScaleType:=3
i = i + 1
Loop
a.Cells(1, 15) = ""
Private Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Object, ByVal Target As PivotTable)
Application.Run ("'Top 95 Data Update.xlsb'!ConditionalFormatting")
End Sub