Addchart2 Top Position Incorrect

curtissc

New Member
Joined
May 2, 2015
Messages
5
The below code successfully creates and formats the chart how I want it, but it is not being positioned correctly. The top position of the chart is not where I want it. If I tell the code to put the top of the chart at A200, the top of the chart is closer to A203. If I tell the code to put the top of the chart at A50, the top of the chart is closer to A51. Any idea what's going on here?


Code:
    Set fversustrange = Union(timedata, forcedata)
    Dim fversustchartdest As String
    fversustchartdest = "A50"
    Set fversustchart = Worksheets("CompositeBeamOutputFiles").Shapes.AddChart2( _
        Style:=-1, _
        XlChartType:=xlXYScatterLinesNoMarkers, _
        Left:=Worksheets("CompositeBeamOutputfiles").Range(fversustchartdest).Left, _
        Top:=Worksheets("CompositeBeamOutputfiles").Range(fversustchartdest).Top, _
        Width:=230, _
        Height:=200, _
        NewLayout:=True).Chart
    With fversustchart
        .SetSourceData Source:=fversustrange
        .ChartTitle.Text = "Applied Force (lbf) Versus Time (ms)"
        .ChartTitle.Font.Size = 10
        .ChartTitle.Font.Bold = True
        .ChartTitle.Font.Underline = True
        .Axes(xlCategory).MaximumScale = Round(WorksheetFunction.Max(tdata), 0)
    End With
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I wasn't able to reproduce the problem you were having, but had to use .AddChart instead of .AddChart2 (because .AddChart2 doesn't exist in Excel 2010).

So.. you might try using .AddChart instead?


Another idea is: maybe the formatting alters the size?

if so, you could try adding just above the last line of your code shown above (i.e. above End With):

Code:
.ChartArea.Top = Worksheets("[COLOR=#333333]CompositeBeamOutputfiles[/COLOR]").Range(fversustchartdest).Top


Finally, is there any code that runs after this piece of code that resizes cells, adds text (which wordwaps), or recalculates the .top parameter?
(Or is it that immediately after this code there's a problem?)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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