Sub CreatePivotTable()
Dim lastRow As Long
Dim i As Long
Sheets("Raw").Activate
Range("A1").Value = "Symbol"
Range("B1").Value = "Client Code"
Range("C1").Value = "Quantity"
Range("D1").Value = "Private"
lastRow = Sheets("Raw").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastRow
If Cells(i, 2).Value = "4001" Or Left(Cells(i, 2).Value, 1) = "T" Or Left(Cells(i, 2).Value, 1) = "M" Then
Cells(i, 2).Value = "Private"
Else
End If
Next i
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Raw!R1C1:R" & lastRow & "C4").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Symbol", _
ColumnFields:="Client Code"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Quantity").Orientation = _
xlDataField
End Sub
|