Hello guys,
I have a big problem. I am writing a macro to create a graph from a table. then I want that this graph is moved to another sheet in the same workbook, but excel crashs each time and then it recovers the file without the last changes I have done
I do't know how to do it, because the same instruction in another macro worked...
this is the code of the function:
it works until
then it craschs.
someone can help me!?!? please!!!
just a note: TREND-.crtx is a template I created.
I have a big problem. I am writing a macro to create a graph from a table. then I want that this graph is moved to another sheet in the same workbook, but excel crashs each time and then it recovers the file without the last changes I have done
I do't know how to do it, because the same instruction in another macro worked...
this is the code of the function:
Code:
Function AddTrend(KPI, EqType, StartEq, EndEq)
Range("A1").Select
Month_Range = Range(Cells(StartEq, 5), Cells(EndEq, 5)).Value
PT_Name = Cells(2, 6).Value
PT_Range = Range(Cells(StartEq, 6), Cells(EndEq, 6)).Value
TGT_Name = Cells(1, 11).Value
KPI_Column = 7
TGT_Column = 11
CaptionAxis = "[%]"
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ApplyChartTemplate ( _
"TREND-.crtx")
' ActiveChart.Name = KPI
KPI_NAME = Cells(2, KPI_Column)
KPI_Range = Range(Cells(StartEq, KPI_Column), Cells(EndEq, KPI_Column)).Value
ActiveChart.SeriesCollection(1).Name = KPI_NAME ActiveChart.SeriesCollection(1).Values = KPI_Range
ActiveChart.SeriesCollection(2).Name = PT_Name ActiveChart.SeriesCollection(2).Values = PT_Range
ActiveChart.SeriesCollection(1).XValues = Month_Range With ActiveChart.ChartTitle
.Caption = KPI
End With
With ActiveChart.Axes(xlValue, xlSecondary)
.HasTitle = True
.MaximumScaleIsAuto = True
.MinimumScaleIsAuto = True
With .AxisTitle
.Caption = "Production Time [h]"
End With
End With
With ActiveChart.Axes(xlValue, xlPrimary)
.HasTitle = True
.MaximumScaleIsAuto = True
.MinimumScaleIsAuto = True
With .AxisTitle
.Caption = CaptionAxis
End With
End With
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Graph - "
ActiveChart.Location Where:=StartEq
End Function
it works until
Code:
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="3 "
someone can help me!?!? please!!!
just a note: TREND-.crtx is a template I created.