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

Im trying to search for data in a pivottable and display in a msgbox

$
0
0

So, I have an Accounting Sheet in which names are entered on a daily basis. I am trying to write some VBA to search those names, one by one after they are typed in another sheet which is an Outstandings Payment Sheet. There is a datewise list of all outstanding payments in that sheet and also a Pivottable for the same data. I am now being able to extract the outstanding payment but I am encountering an error when the name that is searched is not there in the outstandings sheet. I am a novice at VBA and all that I have written so far is by looking at help, forums, copy pasting code and some expirementation.

application defined or object defined error - 1004

Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range
Set KeyCells = Sheets("Accounts").Range("B4:B1000")

If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
    If IsEmpty(Target) Then

    ElseIf IsEmpty(Target.Address) Then

    Else
        MsgBox Target.Value
        Worksheets("OutstandingAndDeposits").Activate
        'Updating Table in Outstandings Sheet
        ActiveSheet.PivotTables("PivotTableOutstandings").PivotCache.Refresh

        Dim search_value As Variant                                           
        ' Get PivotData for the outstandings.
        ' the 1004 error occurs on the next line
        search_value = ActiveSheet.PivotTables("PivotTableOutstandings").GetPivotData("Amount", "Customer", Target)
        MsgBox search_value
        Worksheets("Accounts").Activate
    End If

End If
End Sub

Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>