title: Excel VBA Pivot chart
body: <p>I am trying to write a macro for creating a pivot chart. In a sheet in column D I have the list of users. One username can be number of time in column D. I'm trying to find out % of each username from the overall usercount</p>
  
  <p>I need to draw a column chart, user in X axis and % in Y axis. The chart should start after 3 rows of the last cell in column D. The number of rows in column D will vary every time depending on the sample rate. I am trying this to automate some of the test results.</p>
  
  <p>The code I tried </p>
  
  <pre><code>lastTC = Range("D" &amp; Rows.Count).End(xlUp).Row
  lastTCP = lastTC + 3
  lastTCP1 = lastTC + 10
  lastTCC = lastTC + 18
  
  lastTC = Range("D" &amp; Rows.Count).End(xlUp).Row
  Range("D1", "D" &amp; lastTC).Select
   ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
      ("TOPMEM!$D$1:$D" &amp; lastTC), Version:=xlPivotTableVersion14).CreatePivotTable _
      TableDestination:=("TOPMEM!R1C10"), TableName:="PivotTable5", _
      DefaultVersion:=xlPivotTableVersion14
  
  Sheets("TOPMEM").Select
  Cells(724, 1).Select
  ActiveWorkbook.ShowPivotTableFieldList = True
  With ActiveSheet.PivotTables("PivotTable5").PivotFields("USER")
      .Orientation = xlRowField
      .Position = 1
  End With
  ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
      "PivotTable5").PivotFields("USER"), "Count of USER", xlCount
  
  Range("K1").Select
  With ActiveSheet.PivotTables("PivotTable9").PivotFields("Count of USER")
      .Calculation = xlPercentOfTotal
      .NumberFormat = "0.00%"
  End With
  ActiveWorkbook.ShowPivotTableFieldList = False
  </code></pre>