title: Pivot Chart Macro Recording - Chart Name Causing Run-Time Error
body: <p>Recording a macro of pivot chart creation. Creating a pivot table and chart, and then editing the chart's properties.</p>
  <p>The code runs fine until it tries to to edit the chart's properties. At which point I get this message:</p>
  <blockquote>
  <p>&quot;Run-Time error '2147024809 (80070057)'</p>
  <p>The item with the specified name wasn't found</p>
  </blockquote>
  <p>It seems that the chart naming is the issue. Example: when I record the macro, Excel names the chart &quot;Chart 1&quot;. But when I recreate the scenario, the chart is then called &quot;Chart 2&quot; and so the macro doesn't work. If I go and manually change the name to &quot;Chart 2&quot;, the code finishes executing fine.</p>
  <p>If I try to name the chart while recording the macro, I run into a similar issue. i.e., it tries to change &quot;Chart 1&quot; to &quot;New Chart Name&quot;, but can't find &quot;Chart 1&quot;.</p>
  <p>Not too experienced with VBA, but I assume there is some way to name the chart. I tried adding a simple...</p>
  <p><code>ActiveChart.Name = &quot;Name of this Chart&quot;</code></p>
  <p>...following the creation of the chart, but that didn't work.</p>
  <p>Full code below. Any help is greatly appreicated!</p>
  <pre><code>'
  ' Create_NITS_Pivot Macro
  '
  
  '
      Columns(&quot;A:AE&quot;).Select
      ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
          &quot;'Tags Data Dump'!R1C1:R200C31&quot;, Version:=6).CreatePivotTable _
          TableDestination:=&quot;'NITS Pivot Chart'!R1C1&quot;, TableName:=&quot;PivotTable15&quot;, _
          DefaultVersion:=6
      Sheets(&quot;NITS Pivot Chart&quot;).Select
      Cells(1, 1).Select
      With ActiveSheet.PivotTables(&quot;PivotTable15&quot;)
          .ColumnGrand = True
          .HasAutoFormat = True
          .DisplayErrorString = False
          .DisplayNullString = True
          .EnableDrilldown = True
          .ErrorString = &quot;&quot;
          .MergeLabels = False
          .NullString = &quot;&quot;
          .PageFieldOrder = 2
          .PageFieldWrapCount = 0
          .PreserveFormatting = True
          .RowGrand = True
          .SaveData = True
          .PrintTitles = False
          .RepeatItemsOnEachPrintedPage = True
          .TotalsAnnotation = False
          .CompactRowIndent = 1
          .InGridDropZones = False
          .DisplayFieldCaptions = True
          .DisplayMemberPropertyTooltips = False
          .DisplayContextTooltips = True
          .ShowDrillIndicators = True
          .PrintDrillIndicators = False
          .AllowMultipleFilters = False
          .SortUsingCustomLists = True
          .FieldListSortAscending = False
          .ShowValuesRow = False
          .CalculatedMembersInFilters = False
          .RowAxisLayout xlCompactRow
      End With
      With ActiveSheet.PivotTables(&quot;PivotTable15&quot;).PivotCache
          .RefreshOnFileOpen = False
          .MissingItemsLimit = xlMissingItemsDefault
      End With
      ActiveSheet.PivotTables(&quot;PivotTable15&quot;).RepeatAllLabels xlRepeatLabels
      ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
      ActiveChart.SetSourceData Source:=Range(&quot;'NITS Pivot Chart'!$A$1:$C$18&quot;)
      ActiveChart.PivotLayout.PivotTable.AddDataField ActiveChart.PivotLayout. _
          PivotTable.PivotFields(&quot;NITS 16&quot;), &quot;Sum of NITS 16&quot;, xlSum
      ActiveChart.PivotLayout.PivotTable.AddDataField ActiveChart.PivotLayout. _
          PivotTable.PivotFields(&quot;NITS 17&quot;), &quot;Sum of NITS 17&quot;, xlSum
      ActiveChart.PivotLayout.PivotTable.AddDataField ActiveChart.PivotLayout. _
          PivotTable.PivotFields(&quot;NITS 18&quot;), &quot;Sum of NITS 18&quot;, xlSum
      ActiveChart.Name = &quot;NITS_Chart&quot;
      With ActiveChart.PivotLayout.PivotTable.DataPivotField
          .Orientation = xlRowField
          .Position = 1
      End With
      With ActiveChart.PivotLayout.PivotTable.PivotFields(&quot;Utility Acct/Cust#&quot;)
          .Orientation = xlPageField
          .Position = 1
      End With
      With ActiveChart.PivotLayout.PivotTable.PivotFields(&quot;Sub-account name&quot;)
          .Orientation = xlColumnField
          .Position = 1
      End With
      ActiveSheet.Shapes(&quot;Chart 2&quot;).IncrementLeft -1030.5
      ActiveSheet.Shapes(&quot;Chart 2&quot;).IncrementTop -192.5
  End Sub
  </code></pre>