Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

Compile Error - Expected Array while updating pivot

$
0
0

I'm trying to automate a pivot table to it uses the lowest value of a column as the filter for the pivot.

The value in Cell H6 is what will be updating the filter for the pivot, but I need this value to be dynamic and change to the lowest value in column W, However, the code doesn't work with a formula in the cell as it's not viewing it as a value.

Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 20180702
    Dim xPTable As PivotTable
    Dim xPFile As PivotField
    Dim xStr As String
    On Error Resume Next
    If Intersect(Target, Range("H6:H7")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xPTable = Worksheets("cumulative sales pivot").PivotTables("PivotTable2")
    Set xPFile = xPTable.PivotFields("Issue Day Of Sale ID")
    xStr = Target.Text
    xPFile.ClearAllFilters
    xPFile.CurrentPage = xStr
    Application.ScreenUpdating = True
End Sub

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    Range("H6").Select
    Range("H6").PasteSpecial xlPasteFormulas("=MIN(W:W)")
    Range("H6").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

End Sub

The first part the code works but the second part is giving me

"Compile Error - Expected Array"

Any ideas where i'm going wrong?


Viewing all articles
Browse latest Browse all 88075

Trending Articles