Excel 2010 VBA自定义错误栏负方向错误(创buildboxplot)
我正在制作一个堆积柱形图的箱形图,并使用减号和加号的错误条形成我的箱形图的胡须。 我提到这个在Excel 2010中创build一个boxplot
创build正方向错误栏的代码
.SeriesCollection(4).ErrorBar Direction:=xlY, Include:= _ xlPlusValues, Type:=xlCustom, Amount:="=Sheet3!$B$12:$G$12"
工作但负方向错误栏:
.SeriesCollection(2).ErrorBar Direction:=xlY, Include:= _ xlMinusValues, Type:=xlCustom, Amount:="=Sheet3!$B$9:$G$9"
抛出Runtime error '13': Type mismatch
以下是整个代码:
Sub boxplot() Dim rng As Range Dim cht As Chart Set datasht = ThisWorkbook.Sheets(3) Set rng = getChtrng(8, 12, 2, 7) 'select cell ranges to populate chart datasht.Activate rng.Select Set cht = charts.Add Set cht = cht.Location(Where:=xlLocationAsObject, Name:="Sheet3") With cht .SetSourceData rng .ChartType = xlColumnStacked .SeriesCollection(1).XValues = "=Sheet3!$B$1:$G$1" .HasTitle = True .HasLegend = False .ChartTitle.Text = ThisWorkbook.Sheets(1).Cells(1, 6).Value 'remove min, q1 and max quartile bars .SeriesCollection(1).Select Selection.Format.Fill.Visible = msoFalse .SeriesCollection(2).Select Selection.Format.Fill.Visible = msoFalse .SeriesCollection(5).Select Selection.Format.Fill.Visible = msoFalse 'include top whisker .SeriesCollection(4).ErrorBar Direction:=xlY, Include:= _ xlPlusValues, Type:=xlCustom, Amount:="=Sheet3!$B$12:$G$12" 'include bottom whisker .SeriesCollection(2).ErrorBar Direction:=xlY, Include:= _ xlMinusValues, Type:=xlCustom, Amount:="=Sheet3!$B$9:$G$9" End With End Sub
还有,在vba中创buildboxplot的任何替代方法都是可行的吗?