+ Reply to Thread
Results 1 to 3 of 3

Error in code for pivot table chart

  1. #1
    Registered User
    Join Date
    02-17-2013
    Location
    Arkansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Error in code for pivot table chart

    I am getting an error in my macro code when running a pivot table chart, here is the code:

    Range("F14").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Scans", Version:=xlPivotTableVersion14).CreatePivotTable TableDestination _
    :="[ScannerWKS.xlsm]ScannerWKS!R2C11", TableName:="PivotTable5", _
    DefaultVersion:=xlPivotTableVersion14
    ActiveWorkbook.ShowPivotTableFieldList = True
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("Scanner ID")
    .Orientation = xlRowField
    .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
    "PivotTable5").PivotFields("Scanned"), "Count of Scanned", xlCount
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
    "PivotTable5").PivotFields("Scanned"), "Count of Scanned2", xlCount
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
    "PivotTable5").PivotFields("Scanned"), "Count of Scanned3", xlCount
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("Count of Scanned")
    .Caption = "First Scan"
    .Function = xlMin
    .NumberFormat = "h:mm:ss;@"
    End With
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("Count of Scanned2")
    .Caption = "Last Scan"
    .Function = xlMax
    .NumberFormat = "h:mm:ss;@"
    End With
    ActiveSheet.PivotTables("PivotTable5").PivotFields("Count of Scanned3"). _
    Caption = "Scan Count"
    ActiveSheet.PivotTables("PivotTable5").TableStyle2 = "PivotStyleDark17"
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlConeColClustered
    ActiveChart.SetSourceData Source:=Range("ScannerWKS!$K$2:$N$10")
    ActiveChart.ClearToMatchStyle
    ActiveChart.ChartStyle = 18
    ActiveChart.ClearToMatchStyle
    ActiveChart.ClearToMatchStyle
    ActiveChart.ChartStyle = 20
    ActiveChart.ClearToMatchStyle
    ActiveChart.ClearToMatchStyle
    ActiveChart.ChartStyle = 44
    ActiveChart.ClearToMatchStyle
    ActiveChart.ShowValueFieldButtons = False

    *****The next Line is where the error occurs******

    ActiveSheet.Shapes("Chart 7").IncrementLeft 357
    ActiveSheet.Shapes("Chart 7").IncrementTop 180
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.Shapes("Chart 7").ScaleWidth 0.819791776, msoFalse, _
    msoScaleFromTopLeft
    ActiveSheet.Shapes("Chart 7").ScaleHeight 2.0381944444, msoFalse, _
    msoScaleFromBottomRight
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.Shapes("Chart 7").ScaleWidth 0.9898348171, msoFalse, _
    msoScaleFromTopLeft
    ActiveSheet.Shapes("Chart 7").ScaleHeight 0.9659284497, msoFalse, _
    msoScaleFromBottomRight
    ActiveWorkbook.ShowPivotTableFieldList = False
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Range("K12").Select
    End Sub

    Any help with this issue would be appreciated

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error in code for pivot table chart

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-17-2013
    Location
    Arkansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Error in code for pivot table chart

    my error seems to center around the name of the pivot chart, each time it creates a new chart it adds 1 to the number following the name. I tried to circumvent this by naming the pivot chart but when opening the chart it initially gives it the other name before the macro changes it. Is the any way around this or a wildcard character I could use?

+ 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