Using Excel 2007:
Say I have a list of sales by employee. Employees can have more than one sale, so eache mployee might have 2 or maybe even 5 sales in a month. When I try to chart this information I only want each employee listed once. So the sales need to be consolidated. I made a subtotal for each employee but the charting functions do not work at all. I've tried all kinds of combinations for input data.
Here is a sample of the data. (names are not real)
Sales Rep Name Sales Date Sales Amount Commission Brady Anderson 6/15/2010 $2,500.00 $187.50 Brady Anderson 6/12/2010 $2,200.00 $165.00 David Green 6/12/2010 $1,900.00 $142.50 David Green 6/15/2010 $1,800.00 $135.00 Richard Taylor 6/17/2010 $2,525.00 $189.38 Richard Taylor 6/15/2010 $2,300.00 $172.50 Richard Taylor 6/17/2010 $1,775.00 $133.13 Tasha Johnson 6/19/2010 $1,875.00 $140.63 Tasha Johnson 6/17/2010 $1,825.00 $136.88 Tasha Johnson 6/22/2010 $1,790.00 $134.25 Tasha Johnson 6/15/2010 $1,750.00 $131.25 Tasha Johnson 6/14/2010 $1,750.00 $131.25 Tasha Johnson 6/12/2010 $1,450.00 $108.75 Violet Newhouse 6/22/2010 $1,875.00 $140.63 Violet Newhouse 6/18/2010 $1,950.00 $146.25 Violet Newhouse 6/17/2010 $1,875.00 $140.63 Violet Newhouse 6/12/2010 $1,875.00 $140.63
Last edited by Andy Pope; 12-02-2008 at 04:28 AM.
Hi,
you can create a pivot table and pivot chart for that kind of work. Check out Pivot Table in the help files, and there are lots of threads in this forum, too.
cheers
Teylyn
Exaclty what I was looking to do. How in the world did I not think about pivotcharts!
Now, making that work as a macro is a new challenge.
It looks like I need to replace the references to sheet1 so that can dynamically change. If Sheet1 has already been created then it will error out and the create sheet command will create a sheet2 and then the macro will be lost.
Sub MakeBarChart() ' ' MakeBarChart Macro ' ' ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ "Sales&CommissionList!R5C1:R22C4", Version:=xlPivotTableVersion12). _ CreatePivotTable TableDestination:="Sheet1!R1C1", TableName:="PivotTable1" _ , DefaultVersion:=xlPivotTableVersion12 Sheets.Add Cells(1, 1).Select ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$C$18") ActiveWorkbook.ShowPivotChartActiveFields = True ActiveChart.ChartType = xlColumnClustered With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sales Rep Name") .Orientation = xlRowField .Position = 1 End With ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _ "PivotTable1").PivotFields("Sales Amount"), "Sum of Sales Amount", xlSum ActiveWorkbook.ShowPivotChartActiveFields = False End Sub
Solved! I can't figure out how to change thread title to say Solved.
Set TableDestination to "" and it auto puts it on a new sheet. Thanks for the help.
Sub MakeBarChart() ' ' MakeBarChart Macro ' ' ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ "Sales&CommissionList!R5C1:R22C4", Version:=xlPivotTableVersion12). _ CreatePivotTable TableDestination:="", TableName:="PivotTable1" _ , DefaultVersion:=xlPivotTableVersion12 ActiveSheet.Shapes.AddChart.Select ActiveWorkbook.ShowPivotChartActiveFields = True ActiveChart.ChartType = xlColumnClustered With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sales Rep Name") .Orientation = xlRowField .Position = 1 End With ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _ "PivotTable1").PivotFields("Sales Amount"), "Sum of Sales Amount", xlSum ActiveWorkbook.ShowPivotChartActiveFields = False End Sub
Wow! All that VBA goes right over the top of my head, but I'm glad I put you on the right track
Try to edit your original post and then look near the title where there should be a drop down box for "prefix". Here you can select "[Solved]". But you can only edit your original post for a limited time. After that, you can contact the mods and they can mark it for you.Solved! I can't figure out how to change thread title to say Solved.
cheers
Teylyn
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks