Help with VBA for simple scatter chart

Linus_99

Board Regular
Joined
Aug 28, 2002
Messages
145
Hi,

Wonder if someone can help with code for the following:

Using Excel 2007, I want to plot 2 points on a scatter chart (x,y for BEFORE and x,y for AFTER). Then to join the points with a line (so far OK for a standard scatter chart), however the line needs to be an arrow with the arrowhead pointing to the AFTER data point.

This needs to be generated by VBA, since it's part of another reporting routine.

Any help appreciated. Thanks.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Assuming your xy data is in A1:B3, series name in B1. Before X in A2, Before Y in B2 and After values in row 3.

Code:
Sub Macro1()
'
    Dim objSeries As Series
    Dim objFmt As LineFormat
'
    Range("A1:B3").Select
    With ActiveSheet.Shapes.AddChart.Chart
        .SetSourceData Source:=Range("'Sheet1'!$A$1:$B$3")
        .ChartType = xlColumnClustered
        .ChartType = xlXYScatterLinesNoMarkers
        Set objSeries = .SeriesCollection(1)
        Set objFmt = objSeries.Format.Line
        With objFmt
            .EndArrowheadWidth = msoArrowheadWidthMedium
            .EndArrowheadLength = msoArrowheadLong
            .EndArrowheadStyle = msoArrowheadTriangle
        End With
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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