View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.charting,microsoft.public.excel.programming
Graham Whitehead Graham Whitehead is offline
external usenet poster
 
Posts: 72
Default Error bars in VBA

I have had some problems in the past drawing charts with error bars. After
a while I found that it helps to organise the code a more logical fashion.
Here is an example of something I has lying around which I have just grabbed
for you. Hopefully, you can see where to change bits for your own
requirements.

dim rngData as range
dim rngErrX as range
dim rngErry as range
dim chtChart as chart

With ActiveSheet
Set rngData = Sheets("......").Range(".....")
Set rngErrX = Sheets("......").Range(".....")
Set rngErrY = Sheets("......").Range(".....")
Set chtChart = .ChartObjects.Add(..., ..., ..., ...).Chart
End With

With chtChart
.ChartType = xlXYScatter
.SetSourceData rngData, PlotBy:=xlColumns
with SeriesCollection(1)
.ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth,
Type:=xlCustom, Amount:=rngErrX
.ErrorBar Direction:=xlY, Include:=xlErrorBarIncludeBoth,
Type:=xlCustom, MinusValues:=rngErrY
end with
end with

Hope that helps

wrote in message
oups.com...
Hi everyone,

I am having trouble with some vba code to add error bars to a new
series I am creating. When I run the following code I get a 'ErrorBar
method of Series class failed' error on the first .errorbar line. Can
anyone help me out?

With ActiveChart.SeriesCollection.NewSeries
.name = GraphForm.tbxSeriesName.Value
.Values = Worksheets("Data").Range("B1:B25")
.XValues = Worksheets("Data").Range("A1:A25")
.ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth,
Type:=xlCustom, _
Amount:=Worksheets("Data").Range("C1:C25")
.ErrorBar Direction:=xlY, Include:=xlErrorBarIncludeBoth,
Type:=xlCustom, _
Amount:=Worksheets("Data").Range("D1:D25")
End With

There is probably a better way to do this (add error bars to a new
series) but I am not familiar enough with Excel programming to know
what it is. Thanks for any help in advance.