Hi guy I been stuck with this macro for days now and not able to resolve it please help.
My codes:
Sub time_vs_strain()
Dim chartData As Range
Dim worksheetName As String
Range("B8:E8").Select
Range(Selection, Selection.End(xlDown)).Select
Set chartData = Selection
worksheetName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=chartData, PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Delete
ActiveChart.SeriesCollection(2).Delete
ActiveChart.Location Where:=xlLocationAsObject, Name:=worksheetName
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "time vs strain"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "time "
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "strain"
End With
End Sub
when i ran the macro it give me the error:
"Run time error 5, Invalid Procedure call or argument"
it hightlight the line:
ActiveChart.Location Where:=xlLocationAsObject, Name:=worksheetName
Can you guys please help me. I dont know what to do anymore!
My codes:
Sub time_vs_strain()
Dim chartData As Range
Dim worksheetName As String
Range("B8:E8").Select
Range(Selection, Selection.End(xlDown)).Select
Set chartData = Selection
worksheetName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=chartData, PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Delete
ActiveChart.SeriesCollection(2).Delete
ActiveChart.Location Where:=xlLocationAsObject, Name:=worksheetName
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "time vs strain"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "time "
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "strain"
End With
End Sub
when i ran the macro it give me the error:
"Run time error 5, Invalid Procedure call or argument"
it hightlight the line:
ActiveChart.Location Where:=xlLocationAsObject, Name:=worksheetName
Can you guys please help me. I dont know what to do anymore!