I have a vb application that populates two columns of data, actual production and budgeted production for each day of the current month, in a spreadsheet then creates a line-column chart from that data. I originally recorded a macro in Excel to insert the chart, etc. It runs fine in Excel, but when I run the code copied from the macro and put into the application, I get the following error "Run-time error '1004': Method 'Axes' of object '_Chart' failed.
Any help would be greatly appreciated.
Below is the code from the macro to insert the chart, with my changes for the range of data to be used. The lines giving the error message are hightlighted in red.
myRow is an integer
intDay is the integer portion of yesterday's date
myrow = intDay + 1
MyRange = "A2:B" & CStr(myrow)
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column"
ActiveChart.SetSourceData Source:=Sheets("ARP").Range(myrange), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "ARP Hardwood Production"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "ADMT"
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = False
End With
ActiveChart.HasLegend = False
Any help would be greatly appreciated.
Below is the code from the macro to insert the chart, with my changes for the range of data to be used. The lines giving the error message are hightlighted in red.
myRow is an integer
intDay is the integer portion of yesterday's date
myrow = intDay + 1
MyRange = "A2:B" & CStr(myrow)
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column"
ActiveChart.SetSourceData Source:=Sheets("ARP").Range(myrange), PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "ARP Hardwood Production"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "ADMT"
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = False
End With
ActiveChart.HasLegend = False