开发者

Chart based on two series and two axis in VB (Excel)

I'd like to generate a chart in Excel using VB. The chart needs to have two series. One of them should be displayed as values and the other used as x-axis. How can I do that? Additionally, how to set labels for the series?

Here is my code that plots one set of values on chart:

ActiveChart.ChartType =开发者_运维技巧 xlXYScatterLines
'this sis displayed as y axis (values)
ActiveChart.SeriesCollection.Add Source:=Worksheets("My label").Range("H8:H11") 

Many thanks


Give this a try...

Sub AddNewSeries()
    With ActiveChart.SeriesCollection.NewSeries
        .Name = '//Name of Series Goes Here//
        .Values = Worksheets("My Label").Range("H8:H11")
        '// change with range of intended x-axis values
        .XValues = Worksheets("My Label").Range("A8:A11")
        .HasDataLabels = True 
    End With
End Sub

Read more: Quick Excel Chart VBA Examples

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜