user3770133
user3770133

Reputation:

Defining new chart a location in excel

I am adding a new chart and would like to define its location. I hav tried several approaches with top and left, but with no success. this is my code:

Set sh = ActiveWorkbook.Worksheets(unit)
Set chrt = sh.Shapes.AddChart.Chart

With chrt
    'Data?
    .ChartType = xlXYScatterLines
    .SeriesCollection.NewSeries
    .SeriesCollection(1).name = "=""Scatter Chart"""
    .SeriesCollection(1).XValues = x
    .SeriesCollection(1).Values = y


    'Location
    'DON'T KNOW WHAT TO PUT HERE
    '.location xlLocationAsObject doesn't work!
    'Titles
    .HasTitle = True
    .ChartTitle.Characters.Text = name
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X values"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y values"
    .Axes(xlCategory).HasMajorGridlines = True

    'Formatting
    .Axes(xlCategory).HasMinorGridlines = False
    .Axes(xlValue).HasMajorGridlines = True
    .Axes(xlValue).HasMinorGridlines = False
    .Axes(xlValue).MinimumScaleIsAuto = True
    .Axes(xlValue).MaximumScaleIsAuto = True
    .HasLegend = False
End With

Upvotes: 0

Views: 75

Answers (1)

GBSingh
GBSingh

Reputation: 426

you can use this to set the cell that you want to move your chart to. Just add this outside your loop

sh.ChartObjects.Left = sh.Range("A1")
sh.ChartObjects.Top = sh.Range("A1")

Hope this helps

Upvotes: 1

Related Questions