Code for XY Line Chart.

dager6

New Member
Joined
Aug 1, 2014
Messages
11
Hi All,

I am trying to get a code for my need of a specific XY Line chart:

1. Dynamic rows (may more than 256 limit); 61 Columns
2. Row 1 as X axis
3. All lines .5 Weight, except for last two (2.5 Weight)

Could somebody help me to get the code? My Excel does not let me to record the Macro for chart. Thanks a lot.

Best,

Mat
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How to modify the code below to achieve the goals above?

Code:
Sub EmbeddedChartFromScratch()    Dim myChtObj As ChartObject    Dim rngChtData As Range    Dim rngChtXVal As Range    Dim iColumn As Long    [COLOR=#00C000]' make sure a range is selected[/COLOR]    If TypeName(Selection) <> "Range" Then Exit Sub    [COLOR=#00C000]' define chart data[/COLOR]    Set rngChtData = Selection    [COLOR=#00C000]' define chart's X values[/COLOR]    With rngChtData        Set rngChtXVal = .Columns(1).Offset(1).Resize(.Rows.Count - 1)    End With    [COLOR=#00C000]' add the chart[/COLOR]    Set myChtObj = ActiveSheet.ChartObjects.Add _        (Left:=250, Width:=375, Top:=75, Height:=225)    With myChtObj.Chart        [COLOR=#00C000]' make an XY chart[/COLOR]        .ChartType = xlXYScatterLines        [COLOR=#00C000]' remove extra series[/COLOR]        Do Until .SeriesCollection.Count = 0            .SeriesCollection(1).Delete        Loop        [COLOR=#00C000]' add series from selected range, column by column[/COLOR]        For iColumn = 2 To rngChtData.Columns.Count            With .SeriesCollection.NewSeries                .Values = rngChtXVal.Offset(, iCOlumn - 1)                .XValues = rngChtXVal                .Name = rngChtData(1, iColumn)            End With        Next    End WithEnd Sub</pre>

Thanks,

Matt
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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