VBA - Graph repositioning

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
This is my chart creating macro.
I want to change some parameters of the graph, but get an error:
Automation error

Code:
Sub CreateChart()
Dim jS As Worksheet
Dim jRow As Long
Dim jChart As Chart
Dim jChartRange As Range

    Set jS = ActiveSheet
    Range("A2:B2").Select
    Set jChartRange = Range("A2:B2", Selection.End(xlDown))
    Set jChart = Charts.Add
    jChart.ChartType = xlLineMarkers
    jChart.SetSourceData Source:=jChartRange, PlotBy:=xlColumns
    jChart.Location Where:=xlLocationAsObject, Name:=jS.Name
    With jChart
        .HasTitle = False
        .Parent.Top = 15
        .Parent.Left = 200
        .Axes(xlCategory, xlPrimary).HasTitle = False
        .Axes(xlValue, xlPrimary).HasTitle = False
        .HasLegend = False
        .HasDataTable = False
    End With
End Sub

Whre is my mistake?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Just a guess, but aren't you changing what type of object jChart is after your created it? I should imagine that would cause problems. Use ActiveChart, or redefine your object after you've reset what the chart is, like:
Code:
    jChart.Location Where:=xlLocationAsObject, Name:=jS.Name
    Set jChart = ActiveChart
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,774
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top