分享

VBA在Excel中的应用(三)

 Excel实用知识 2021-11-20
复制代码
复制代码
'Common Excel Chart Types      
'-------------------------------------------------------------------   
'Chart   |   VBA Constant (ChartType property of Chart object)     | 
'==================================================================        
'Column  |   xlColumnClustered, xlColumnStacked, xlColumnStacked100|         
'Bar     |   xlBarClustered, xlBarStacked, xlBarStacked100         | 
'Line    |   xlLine, xlLineMarkersStacked, xlLineStacked           | 
'Pie     |   xlPie, xlPieOfPie                                     | 
'Scatter |   xlXYScatter, xlXYScatterLines                         | 
'------------------------------------------------------------------- 

Public Sub AddChartSheet() 
    Dim dataRange As Range 
    Set dataRange = ActiveWindow.Selection 
    Charts.Add   'Create a chart sheet 
    With ActiveChart    'Set chart properties 
        .ChartType = xlColumnClustered 
        .HasLegend = True 
        .Legend.Position = xlRight 

        .Axes(xlCategory).MinorTickMark = xlOutside 
        .Axes(xlValue).MinorTickMark = xlOutside 
        .Axes(xlValue).MaximumScale = _ 
                    Application.WorksheetFunction.RoundUp( _ 
                    Application.WorksheetFunction.Max(dataRange), -1) 
        .Axes(xlCategory).HasTitle = True 
        .Axes(xlCategory).AxisTitle.Characters.Text = 'X-axis Labels' 
        .Axes(xlValue).HasTitle = True 
        .Axes(xlValue).AxisTitle.Characters.Text = 'Y-axis' 

        .SeriesCollection(1).name = 'Sample Data' 
        .SeriesCollection(1).Values = dataRange 
    End With 
End Sub
复制代码
复制代码

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多