Hola
I have been searching the forum looking for an issue that has been poking me this week.
I´ll give a brief description. I have a macro that load, decorate and create pivot tables from a report. Depends of the needs, my boss needs to create a set of reports (from the main one) that automatically will create pivot tables and the grafics. So far I got all working but there is a twist in the you-can-do-better. I have a sheet where different tables can be created by choosing the fields, and there you can choose the type of graph. The twist is to use two types of graphs in the same chart.
I have tried this but wont work
The issue comes in the marked line, I dont know how I can choose, one or the other serie to change the graph type.
Any help will be appreciated.
Many thanks
Alb
I have been searching the forum looking for an issue that has been poking me this week.
I´ll give a brief description. I have a macro that load, decorate and create pivot tables from a report. Depends of the needs, my boss needs to create a set of reports (from the main one) that automatically will create pivot tables and the grafics. So far I got all working but there is a twist in the you-can-do-better. I have a sheet where different tables can be created by choosing the fields, and there you can choose the type of graph. The twist is to use two types of graphs in the same chart.
I have tried this but wont work
Code:
Sub graficcore()
tablacore
tabladest = Cells(1, 1).Address
With ActiveSheet.UsedRange
LastRow = .Rows(.Rows.Count).Row
LastColumn = .Columns(.Columns.Count).Column
End With
tabladest = Cells(1, 1).Address
ultimacelda = Cells(LastRow, LastColumn).Address
down1 = 330 'LastRow * 15 + 30
right1 = 60 'LastColumn * 60 + 120
If LastRow > 20 And LastColumn > 10 Or LastRow > 20 And LastColumn < 10 Then down = LastRow * 15 + 30
With Worksheets(boook(t)).Shapes.AddChart(Left:=(right1), Top:=(down1), Width:=540, Height:=360).Select
ActiveChart.ChartObjects().Activate <--------ISSUE
If ga(t) = "" Then ActiveChart.SeriesCollection(1).ChartType = xlColumnField
If ga(t) = "Column" Then
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ChartType = xlColumnField
End If
If ga(t) = "Line" Then ActiveChart.SeriesCollection(1).ChartType = xlLineMarkers
If ga(t) = "Pie" Then ActiveChart.SeriesCollection(1).ChartType = xlPie
If ga(t) = "Bar" Then ActiveChart.SeriesCollection(1).ChartType = xlBarStacked
If ga(t) = "Ring" Then ActiveChart.SeriesCollection(1).ChartType = xlBarOfPie
If ga2(t) = "Colum" Then ActiveChart.SeriesCollection(2).ChartType = "xlColumnField"
If ga2(t) = "Line" Then
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).ChartType = xlLineMarkers
End If
If ga(t) = "Ring" Or ga(t) = "Pie" Then gaf2 = ""
ActiveChart.ChartStyle = 1
ActiveChart.ApplyLayout (2)
ActiveWorkbook.ShowPivotChartActiveFields = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveChart.Refresh
End With
End Sub
The issue comes in the marked line, I dont know how I can choose, one or the other serie to change the graph type.
Any help will be appreciated.
Many thanks
Alb