您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > Excel-VBA自动插入多个曲线图
vba添加曲线有几十个部门,我想每个销售部得到一个曲线图,就像第一个图那样,我写的代码如下:Sub逐个插入图表()'在指定位置作图'清除已有图表nohang=Range(c65536).End(xlUp).RowForEachrInSheets(销售数据).ChartObjectsr.DeleteNextDimabAsRangeDimeAsRangeDimbbbAsChartObjectDimxxAsInteger,yyAsInteger,zzAsIntegerForm=1To3Step1xx=(m-1)*20+4yy=(m-1)*20+22zz=m*3Sete=Range(Range(Cells(441,2),Cells(nohang,2)),Range(Cells(441,zz),Cells(nohang,zz+2)))Setab=Range(b&xx,i&yy)'生成图表的位置Setbbb=ActiveSheet.ChartObjects.Add(ab.Left,ab.Top,ab.Width,ab.Height)Withbbb.Chart.ChartType=xlLine'折线图.SetSourceDataSource:=e'数据源'以下是图表属性设置With.Axes(xlValue).MinimumScaleIsAuto=True.MaximumScaleIsAuto=True.MinorUnitIsAuto=True.MajorUnitIsAuto=True.Crosses=xlAutomatic.ReversePlotOrder=False.ScaleType=xlLinear.DisplayUnit=xlTenThousands.HasDisplayUnitLabel=TrueEndWithWith.Axes(xlCategory).TickLabels.AutoScaleFont=TrueWith.TickLabels.Font.Name=宋体.FontStyle=常规.Size=9.Strikethrough=False.Superscript=False.Subscript=False.OutlineFont=False.Shadow=False.Underline=xlUnderlineStyleNone.ColorIndex=xlAutomatic.Background=xlAutomaticEndWithEndWithWith.Legend.AutoScaleFont=True.Position=xlTop.Height=24With.Font.Name=宋体.FontStyle=常规.Size=9.Strikethrough=False.Superscript=False.Subscript=False.OutlineFont=False.Shadow=False.Underline=xlUnderlineStyleNone.ColorIndex=xlAutomatic.Background=xlAutomaticEndWithEndWithWith.SeriesCollection(1)With.Border.ColorIndex=6.Weight=xlMedium.LineStyle=xlContinuousEndWith.MarkerBackgroundColorIndex=xlNone.MarkerForegroundColorIndex=xlNone.MarkerStyle=xlNone.Smooth=False.MarkerSize=3.Shadow=FalseEndWithWith.SeriesCollection(2)With.Border.ColorIndex=5.Weight=xlMedium.LineStyle=xlContinuousEndWith.MarkerBackgroundColorIndex=xlNone.MarkerForegroundColorIndex=xlNone.MarkerStyle=xlNone.Smooth=False.MarkerSize=3.Shadow=FalseEndWithWith.SeriesCollection(3)With.Border.ColorIndex=3.Weight=xlMedium.LineStyle=xlContinuousEndWith.MarkerBackgroundColorIndex=xlNone.MarkerForegroundColorIndex=xlNone.MarkerStyle=xlNone.Smooth=False.MarkerSize=3.Shadow=FalseEndWith'图表属性设置结束EndWithSete=NothingSetbbb=NothingNextmEndSub求大侠帮忙改改,小弟先谢过了SubZxd()DimShAsWorksheeti=1ForEachShInSheetsSh.ChartObjects(1).ActivateActiveChart.SetSourceDataSource:=Sheets(z&i).Range(A2:E2,A4:E4,A5:E5),_PlotBy:=xlRowsi=i+1NextEndSubCharts.AddActiveChart.ChartType=xlXYScatterSmoothActiveChart.SetSourceDataSource:=Sheets(Sheet1).Range(I7)ActiveChart.SeriesCollection.NewSeriesActiveChart.SeriesCollection(1).XValues==Sheet1!R7C2:R14C2ActiveChart.SeriesCollection(1).Values==Sheet1!R7C3:R14C3ActiveChart.LocationWhere:=xlLocationAsObject,Name:=Sheet1Fori=1ToActiveSheet.ChartObjects.Countr=(i-1)*40+4WithActiveSheet.ChartObjects(i).Chart.SeriesCollection(1).XValues==热处理委托单!I&r+1&:N&r+1.SeriesCollection(1).Values==热处理委托单!I&r&:N&rEndWithNextForr=1To100Charts.AddActiveChart.ChartType=xlLineMarkersActiveChart.SetSourceDataSource:=Sheets(Sheet1).Range(A&r&:E&r)'ActiveChart.LocationWhere:=xlLocationAsObject,Name:=Sheet1'删除本句前的'可将各个图表作为对象插入sheet1中,否则各图表将单独作为chart表插入工作簿。NextChartType属性适用于Chart对象,Series对象描述返回或设置图表类型。Long类型,可读写。可为下列XlChartType常量。图表类型说明常量柱形图簇状xlColumnClustered三维簇状柱形图xl3DColumnClustered堆积柱形图xlColumnStacked三维堆积柱形图xl3DColumnStacked百分比堆积柱形图xlColumnStacked100三维百分比堆积柱形图xl3DColumnStacked100三维柱形图xl3DColumn簇状条形图簇状条形图xlBarClustered三维簇状条形图xl3DBarClustered堆积条形图xlBarStacked三维堆积条形图xl3DBarStacked百分比堆积条形图xlBarStacked100三维百分比堆积条形图xl3DBarStacked100折线图折线图xlLine数据点折线图xlLineMarkers堆积折线图xlLineStacked堆积数据点折线图xlLineMarkersStacked百分比堆积折线图xlLineStacked100百分比堆积数据点折线图xlLIneMarkersStacked100折线图三维折线图xl3DLine饼图饼图xlPie分离型饼图xlPieExploded三维饼图xl3Dpie三维分离型饼图xl3DPieExploded复合饼图xlPieOfPie饼图复合柱饼图xlBarOfPieXY(散点图)散点图xlXYScatter平滑线散点图xlXYScatterSmooth无数据点折线散点图xlXYScatterLinesNoMarkers折线散点图xlXYScatterLines无数据点折线散点图xlXYScatterLinesNoMarkers气泡图气泡图xlBubble三维气泡图xlBubble3DEffect面积图面积图xlArea三维面积图xl3DArea堆积面积图xlAreaStacked三维堆积面积图xl3DAreaStacked百分比堆积面积图xlAreaStacked100三维百分比堆积面积图xl3DAreaStacked100圆环图圆环图xlDoughnut分离型圆环图xlDoughnutExploded雷达图雷达图xlRadar数据点雷达图xlRadarMarkers填充雷达图xlRadarFilled曲面图三维曲面图xlSurface曲面图(俯视图)xlSurfaceTopView三维曲面图(框架图)xlSurfaceWireframe曲面图(俯视框架图)xlSurfaceTopViewWireframe股价图盘高-盘低-收盘图xlStockHLC成交量-盘高-盘低-收盘图xlStockVHLC开盘-盘高-盘低-收盘图xlStockOHLC成交量-开盘-盘高-盘低-收盘图xlStockVOHLC圆柱图簇状柱形圆柱图xlCylinderColClustered簇状条形圆柱图xlCylinderBarClustered堆积柱形圆柱图xlCylinderColStacked堆积条形圆柱图xlCylinderBarStacked百分比堆积柱形圆柱图xlCylinderColStacked100百分比堆积条形圆柱图xlCylinderBarStacked100三维柱形圆柱图xlCylinderCol圆锥图簇状柱形圆锥图xlConeColClustered簇状条形圆锥图xlConeBarClustered堆积柱形圆锥图xlConeColStacked堆积条形圆锥图xlConeBarStacked百分比堆积柱形圆锥图xlConeColStacked100百分比堆积条形圆锥图xlConeBarStacked100三维柱形圆锥图xlConeCol棱锥图簇状柱形棱锥图xlPyramidColClustered簇状条形棱锥图xlPyramidBarClustered堆积柱形棱锥图xlPyramidColStacked堆积条形棱锥图xlPyramidBarStacked百分比堆积柱形棱锥图xlPyramidColStacked100百分比堆积条形棱锥图xlPyramidBarStacked100三维柱形棱锥图xlPyramidCol
本文标题:Excel-VBA自动插入多个曲线图
链接地址:https://www.777doc.com/doc-3042070 .html