我正在编写一个Excel宏,该宏应创建一个带有自定义错误栏的条形图(均值的标准错误,在工作表上计算)。但是我坚持包括值。

问题描述 投票:0回答:1

应在条形图中显示平均值,应将计算出的组标准错误作为误差条的值添加。

这是VBA代码:

Dim ValueCell as Range Set ValueCell = Range("B98:C103") ValueCell.Select ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select ActiveChart.FullSeriesCollection(1).HasErrorBars = True Set ValueCell = Worksheets(SHEET_NAME).Range(Cells(108, 3), Cells(112, 3)) ActiveChart.FullSeriesCollection(1).ErrorBar Direction:=xlY, _ Include:=xlPlusValues, Type:=xlCustom, Amount:=ValueCell, _ PlusValues:=ValueCell screenshot example 当我包括Amount

和/或

PlusValues

参数时,它被卡住了。我得到了“应用程序定义或对象定义的错误”。运行代码后,它包含图形,但带有

fixed

错误栏。 我搜索了类似的答案,但是我的代码似乎没有任何作用。我尝试了这两个参数(范围,数组)的不同格式,但似乎没有任何作用。我还尝试记录一个宏,然后提取所需的代码,但这无济于事。 应该有可能,但我不知道该怎么办。
	

该代码对我有用: Sub AddChartWithErrors() Dim Sheet_Name As String Sheet_Name = "Arkusz2" With ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Chart .SetSourceData Source:=Worksheets(Sheet_Name).Range("$B$3:$C$8") .FullSeriesCollection(1).HasErrorBars = True .FullSeriesCollection(1).ErrorBar Direction:=xlY, Include:= _ xlPlusValues, Type:=xlCustom, Amount:=Worksheets(Sheet_Name).Range("$C$13:$C$18") .Axes(xlValue).TickLabels.NumberFormat = "General" End With End Sub

excel vba bar-chart excel-2010
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.