【问题标题】:Excel 2010 VBA Custom Error Bar Minus Direction Error (Creating a boxplot)Excel 2010 VBA 自定义错误栏减去方向错误(创建箱线图)
【发布时间】:2017-07-11 09:01:19
【问题描述】:

我正在从堆积柱形图制作箱线图,并使用减号和加号误差线来形成我的箱线图的胡须。 i referred to this to create a boxplot in Excel 2010

创建正方向误差条的代码

.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 中创建箱线图的任何替代方法肯定有效?

【问题讨论】:

  • 我没有经常使用图表来确定,但是你的问题是否有理由说你为SeriesCollection(4)设置了xlMinusValues,但你的代码显示你为SeriesCollection(2)设置了它?
  • 对不起,我只是在试验这些值

标签: vba excel boxplot errorbar


【解决方案1】:

ErrorBar 的语法如下: .ErrorBar( 方向 , 包括 , 类型 , 金额 , 减值 )

当 Type 为 xlErrorBarTypeCustom 时,哪个 Amount 仅用于正误差量,而 MinusValues 仅用于负误差量。

因此,您需要将 MinusValues 的语句更改为以下内容:

.SeriesCollection(2).ErrorBar Direction:=xlY, Include:= _
        xlMinusValues, Type:=xlCustom, _
        Amount:="=Sheet3!$B$9:$G$9", MinusValues:="=Sheet3!$B$9:$G$9"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多