Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default how to add error bars into bar chart

Dear All,

I am trying to use following code to create a bar chart with error
bar. But " .ErrorBar Direction:=xlY, Include:=xlBoth,
Type:=xlCustom, Amount:=errBar" doesn't work.

Could anyone help me figure out how to handle this?

Thanks

John




Sub DrawBarChart2()
Dim barChart As ChartObject
Dim titles, srcData, errBar As Range

Application.ScreenUpdating = False

Set barChart =
ActiveSheet.ChartObjects.Add(Left:=Range("H1").Lef t,
Top:=Range("H1").Top, Width:=Range("A3:E18").Width,
Height:=Range("A3:E18").Height)

Set titles = Range("A1:F1") ' data: g1 g2 g3 g4 g5 g6
Set srcData = Range("A2:F2") ' data: 11.594816 17.29588
8.554076 14.671445 9.924798 10.263842
Set srcData = Union(titles, srcData)
Set errBar = Range("A3:F3") ' data: 3.299938235 1.630907253
0.883572613 3.966173892 2.840271819 2.192138694

With barChart
.Chart.SetSourceData Source:=srcData, PlotBy:=xlRows
.Chart.ChartType = xlColumnClustered
.Chart.Axes(xlValue).MajorGridlines.Delete
.Chart.Legend.Delete
.Chart.Axes(xlValue).HasTitle = True
.Chart.Axes(xlValue).AxisTitle.Text = "Group mean with std
error bar"
.Chart.Axes(xlCategory).HasTitle = True
.Chart.Axes(xlCategory).AxisTitle.Text = "groups"
.Chart.HasTitle = True
.Chart.ChartTitle.Text = "Bar chart with std errors"
With .Chart.SeriesCollection(1)
.HasErrorBars = True
.ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlCustom,
Amount:=errBar
End With
End With
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default how to add error bars into bar chart

hi John,

we must add these two arguments

Amount Optional Variant. Amount of the error. Used only for the amount of a positive error
when Type is set xlErrorBarTypeCustom.

MinusValues €‹€‹Optional Variant. Amount of negative error
when Type is set xlErrorBarTypeCustom.

..ErrorBar Direction:=xlY, Include:=xlErrorBarIncludeBoth, Type:=xlErrorBarTypeCustom, Amount:=1, MinusValues:=-5

--
isabelle


Le 2011-12-06 16:55, John Smith a écrit :
Dear All,

I am trying to use following code to create a bar chart with error
bar. But " .ErrorBar Direction:=xlY, Include:=xlBoth,
Type:=xlCustom, Amount:=errBar" doesn't work.

Could anyone help me figure out how to handle this?

Thanks

John




Sub DrawBarChart2()
Dim barChart As ChartObject
Dim titles, srcData, errBar As Range

Application.ScreenUpdating = False

Set barChart =
ActiveSheet.ChartObjects.Add(Left:=Range("H1").Lef t,
Top:=Range("H1").Top, Width:=Range("A3:E18").Width,
Height:=Range("A3:E18").Height)

Set titles = Range("A1:F1") ' data: g1 g2 g3 g4 g5 g6
Set srcData = Range("A2:F2") ' data: 11.594816 17.29588
8.554076 14.671445 9.924798 10.263842
Set srcData = Union(titles, srcData)
Set errBar = Range("A3:F3") ' data: 3.299938235 1.630907253
0.883572613 3.966173892 2.840271819 2.192138694

With barChart
.Chart.SetSourceData Source:=srcData, PlotBy:=xlRows
.Chart.ChartType = xlColumnClustered
.Chart.Axes(xlValue).MajorGridlines.Delete
.Chart.Legend.Delete
.Chart.Axes(xlValue).HasTitle = True
.Chart.Axes(xlValue).AxisTitle.Text = "Group mean with std
error bar"
.Chart.Axes(xlCategory).HasTitle = True
.Chart.Axes(xlCategory).AxisTitle.Text = "groups"
.Chart.HasTitle = True
.Chart.ChartTitle.Text = "Bar chart with std errors"
With .Chart.SeriesCollection(1)
.HasErrorBars = True
.ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlCustom,
Amount:=errBar
End With
End With
Application.ScreenUpdating = True
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add error bars into bar chart John Smith[_8_] Charts and Charting in Excel 0 December 6th 11 07:35 PM
Customise error bars on individual bars in a bar chart 2007 Millie Charts and Charting in Excel 2 April 25th 09 04:16 AM
chart error bars Paula Galloway Excel Programming 5 April 7th 09 05:07 PM
XL 2007 Chart Error Bars Bernard Liengme Charts and Charting in Excel 2 May 28th 08 02:09 AM
How to add error bars to 3-D chart Shijia Excel Discussion (Misc queries) 2 November 20th 07 09:48 PM


All times are GMT +1. The time now is 03:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"