Question : Summed Pivot table

Hello Experts
 I am looking to create a pivot table , I believe from the following raw data. Every month I will get a set of raw data (tab raw) and I rearrange to look readable format(finished). So the raw data is only a subset and every  month the amounts and length of the report is different. What does stay constant is the clients (or mostly) .I tried using sums and pivot table, but the problem is that the some of the clients need to be summed while others do not. In the raw data I manually typed in a row called sum and put in the Y for summed or N to be left as is. The column sum is not normally there . So what I am trying to achieve is a vba script that will tramform the data into my readable finished product
Attachments:
 
sample3
 

Answer : Summed Pivot table

OK, try this:

There is no need to manually add in Private or a Sum column anymore, as the macro does this for you.  As I was trying to state earlier, in order for this to be automated, I need some kind of logical way that these records are marked private or y or n.

And this is what I needed to know:
"Client codes beginning with M , and T and account 4001 needed to be added together for each symbol."


Also, the latest file you posted has all of the proper data, so now that amounts match to what you expected.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
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
 
Example
 
Random Solutions  
 
programming4us programming4us