title: Create Pivot Table
body: <p>I got this Run-time error '1004':- This command requires at least two rows of source data. You cannot use the command on a selection in only one row. Try the following: If you're using an advanced filter, select a range of cells that contains at least two rows of data. Then click the Advanced Filter command again. If you're creating a PivotTable report or PivotChart report, type a [it stops here]</p>
  
  <p>I got the aforementioned error at:- </p>
  
  <pre><code>pvc.CreatePivotTable TableDestination:=Worksheets("TABLE").Range("A1"), _
  TableName:="INFO", DefaultVersion:=xlPivotTableVersion12
  </code></pre>
  
  <p>I'm trying to run this code:-</p>
  
  <pre><code>Sub CreateTable()
  Dim lastRow As Long
  Dim pvc As PivotCache
   lastRow = ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row
      ActiveWorkbook.Names.Add Name:="Database", RefersTo:="=DATA!$G$1:$K$" &amp; lastRow
  Set pvc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
          "Database", Version:=xlPivotTableVersion12)
  pvc.CreatePivotTable TableDestination:=Worksheets("TABLE").Range("A1"), _
  TableName:="INFO", DefaultVersion:=xlPivotTableVersion12
      Sheets("TABLE").Select
      Cells(1, 1).Select
      ActiveWorkbook.ShowPivotTableFieldList = True
      With ActiveSheet.PivotTables("INFO").PivotFields("MODEL")
          .Orientation = xlRowField
          .Position = 1
      End With
      With ActiveSheet.PivotTables("INFO").PivotFields("TYPE")
          .Orientation = xlRowField
          .Position = 2
      End With
      ActiveSheet.PivotTables("INFO").AddDataField ActiveSheet.PivotTables( _
      "INFO").PivotFields("GRADE"), "Sum of GRADE", xlSum
      ActiveSheet.PivotTables("INFO").AddDataField ActiveSheet.PivotTables( _
      "INFO").PivotFields("SIZE"), "Sum of SIZE", xlSum
      ActiveSheet.PivotTables("INFO").AddDataField ActiveSheet.PivotTables( _
      "INFO").PivotFields("QTY"), "Sum of QTY", xlSum
      With ActiveSheet.PivotTables("INFO").PivotFields("MODEL")
          .Orientation = xlColumnField
          .Position = 2
      End With
      With ActiveSheet.PivotTables("INFO").PivotFields("TYPE")
          .Orientation = xlColumnField
          .Position = 3
      End With
      With ActiveSheet.PivotTables("INFO").PivotFields("Sum of GRADE")
          .Orientation = xlPINFOField
          .Position = 1
      End With
      With ActiveSheet.PivotTables("INFO").PivotFields("Sum of SIZE")
          .Orientation = xlRowField
          .Position = 1
      End With
      ActiveWorkbook.ShowPivotTableFieldList = False
      Range("B3").Select
      ActiveSheet.PivotTables("INFO").CompactLayoutColumnHeader = "MODEL"
      Range("A5").Select
      ActiveSheet.PivotTables("INFO").CompactLayoutRowHeader = "SIZE"
      Range("A1").Select
      ActiveSheet.PivotTables("INFO").PivotFields("GRADE").Caption = "GRADE"
      Cells.Select
      Cells.EntireColumn.AutoFit
      Columns("B:BB").Select
      Selection.Style = "Comma"
      Cells.Select
      Cells.EntireColumn.AutoFit
      Range("C1").Select
  End Sub
  </code></pre>
  
  <p>Pls help.</p>
  
  <p>Thanks.</p>