excel2007制作柏拉图问题
刚刚在网上看到一个哥们用VBA在EXCEL2010下做了段程序,可自动生成柏拉图。 小弟愚昧,不清楚如何使用下面的代码来自动生成柏拉图,哪位大哥知道,请告诉兄弟,最好上传个excel样例!兄弟不胜感激! 以下是程序源代码 '数据区域的左上角位置常量 Const UpperLeftPos = "B4" Const UpperPos = "B" Const LeftPos = 4 Sub 绘制标准柏拉图() Dim Range1 As Range '选择数据区域,Range("B2")这个格子里放的是有效数据的行数,即分类的总个数 Set Range1 = Range(UpperLeftPos & ":" & Chr(Asc(UpperPos) + 1) & (LeftPos + Range("B2")) & "," & Chr(Asc(UpperPos) + 2) & LeftPos & ":" & Chr(Asc(UpperPos) + 2) & (LeftPos + Range("B2") + 1)) '插入柱形图 ActiveSheet.Shapes.AddChart.Select ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData Source:=Range1 '把百分比数据系列的图形格式变为“带数据值的折线图”,并画在由次要横坐标和次要纵坐标里 ActiveChart.SeriesCollection(2).Select ActiveChart.SeriesCollection(2).AxisGroup = 2 ActiveChart.SeriesCollection(2).ChartType = xlLineMarkers ActiveChart.SetElement (msoElementSecondaryCategoryAxisWithoutLabels) ActiveChart.SetElement (msoElementSecondaryCategoryAxisShow) '把次要横坐标的值显示到刻度上,而不是刻度中间,并隐藏次要横坐标的显示 ActiveChart.Axes(xlCategory, xlSecondary).Select Selection.MajorTickMark = xlNone Selection.TickLabelPosition = xlNone ActiveChart.Axes(xlCategory, xlSecondary).AxisBetweenCategories = False '调整柱形图的显示,去掉相邻柱子的间距,并给每个柱子加外框 ActiveChart.SeriesCollection(1).Select ActiveChart.ChartGroups(1).GapWidth = 0 With Selection.Format.Line .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorText1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = 0 End With With Selection.Format.Line .Visible = msoTrue .Weight = 1 End With '修改主要纵坐标,满值为累加和 ActiveChart.Axes(xlValue).Select ActiveChart.Axes(xlValue).CrossesAt = 0 Selection.MajorTickMark = xlInside ActiveChart.Axes(xlValue).MinimumScale = 0 ActiveChart.Axes(xlValue).MaximumScale = Range(Chr(Asc(UpperPos) + 3) & (LeftPos + Range("B2") + 1)) '修改次要纵坐标,满值为100% ActiveChart.Axes(xlValue, xlSecondary).Select ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = 1 ActiveChart.Axes(xlValue, xlSecondary).MinimumScale = 0 Selection.MajorTickMark = xlInside ActiveChart.Axes(xlValue, xlSecondary).CrossesAt = 1 Selection.TickLabels.NumberFormat = "0%" '让百分比折线上的点显示出具体的数值 ActiveChart.SeriesCollection(2).Select ActiveChart.SeriesCollection(2).ApplyDataLabels ActiveChart.SeriesCollection(2).DataLabels.Select Selection.Position = xlLabelPositionRight '隐去横向的主要网格线 ActiveChart.Axes(xlValue).Select ActiveChart.Axes(xlValue).MajorGridlines.Select Selection.Format.Line.Visible = msoFalse '为图表添加标题,标题的内容放在Range("B1")格子里 ActiveChart.SetElement (msoElementChartTitleAboveChart) ActiveChart.ChartTitle.Select ActiveChart.ChartTitle.Text = Range("B1") End Sub
您可以这样操作: 把这些代码粘贴至Excel的VBA代码窗口中,然后保存,最后运行这个EXCEL文件,您就可以看到效果了。
答:排列图又称为柏拉图,由此图的发明者19世纪意大利经济学家柏拉图(Pareto)的名字而得名。柏拉图最早用排列图分析社会财富分布的状况,他发现当时意大利80%财富...详情>>