+ Reply to Thread
Results 1 to 2 of 2

Macro Pivot Table vs Manual Pivot Table - different results

  1. #1
    Registered User
    Join Date
    05-20-2008
    Posts
    5

    Macro Pivot Table vs Manual Pivot Table - different results

    Hi there,

    Is there a known issue creating pivot tables with macros giving different results than when creating pivot tables manually?

    I recorded a macro for creating a pivot table (edited it a little in some parts) to automate a process and each time I run it, the data/results in the pivot table that it gives me are different then if I create the pivot table manually (w/o the macro). I'm not doing anything different in the macro (aside from a prompt to open the file that I want and to save it at the end).

    I have no idea why this is happening but it's quite annoying. I even included checks to make sure that all the data is included (in case some rows were missed) and I can't figure out the issue.

    Here is the bulk of it. I have no idea why it's behaving so weird and would certainly entertain any thoughts on how to correct this issue.

    Thank you in advance
    -----------
    Sub standings()
    '
    importFILE = Application.GetOpenFilename("Text,*.*")
    Workbooks.OpenText Filename:=importFILE, DataType:=xlDelimited, Comma:=True
    ' dump out if Cancel is Hit
    If importFILE = "False" Then Exit Sub
    Rows("1:11").Select
    Selection.Delete Shift:=xlUp
    ' Count number of rows with data to use for SourceData in pivot table
    sLastRow = Sheets(1).Rows.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Address
    numRows = Mid(sLastRow, InStrRev(sLastRow, "$") + 1)
    ' Test the count and display on screen
    ' MsgBox numRows
    ' To apply this to your statement you could use:
    Dim sourceDataRange As String
    sourceDataRange = "R1C1:R" & numRows & "C34"
    ' Show me the RANGE!!
    MsgBox ActiveSheet.Name
    MsgBox sourceDataRange
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
    "" & ActiveSheet.Name & "!R1C1:R" & numRows & "C34").CreatePivotTable TableDestination:="", TableName _
    :="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
    "current_owner_salesrep")
    .Orientation = xlRowField
    .Position = 1
    End With
    Sheets("Sheet1").Name = "PivotTable"
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("extended_netprice"), "Sum of extended_netprice", _
    xlSum
    ActiveWorkbook.ShowPivotTableFieldList = False
    Application.CommandBars("PivotTable").Visible = False

  2. #2
    Registered User
    Join Date
    05-20-2008
    Posts
    5
    Hrm, no response

    -----
    ' Count number of rows with data to use for SourceData in pivot table
    sLastRow = Sheets(1).Rows.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Address
    numRows = Mid(sLastRow, InStrRev(sLastRow, "$") + 1)
    ' Test the count and display on screen
    ' MsgBox numRows
    ' To apply this to your statement you could use:
    Dim sourceDataRange As String
    sourceDataRange = "R1C1:R" & numRows & "C34"
    ' Show me the RANGE!!
    MsgBox ActiveSheet.Name
    MsgBox sourceDataRange
    -----

    I use the section above to make sure that the range used for the pivot table is correct. When I run the macro, it does give me correct range of the data. However, the numbers it spits out in the actual pivot table are not on par with the numbers a manually created pivot table shows.

    I don't know what the issue here is, if anyone could shed some light on this I would appreciate it, it's frustrating and I'm annoyed with having to create the pivot tables automatically.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1