Macro to edit Error Bars

postal302

New Member
Joined
Oct 29, 2012
Messages
4
Hello all!

I need to figure how to control either the X or Y axis error bars for a scatter chart.

I'm building something like a gantt chart and I only want to use the X axis error bars and delete the Y axis bars. I've been able to add error bars by using "ActiveChart.SeriesCollection(1).HasErrorBars = True" but when i select the error bars using "ActiveChart.SeriesCollection(1).ErrorBars.Select" the Y axis (Vertical Error Bars) are automatically selected and any formatting I apply is added to the Y axis and left off of the X axis.

Does anyone know how to delete the Y axis error bars and/or choose only the X axis error bars?

Thanks in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi and welcome to the forum.

Edit the error bars while recording a macro. The recorded macro often will show you the VBA commands and syntax you're looking for.
 
Upvote 0
That is a great suggestion, and for most cases has worked for me, but in this case it has fallen short. When adding error bars and formatting them (including changing the line color to gradient, setting the colors and stops and setting the line thickness) this is what the macro recorder fed back:

ActiveChart.SeriesCollection(1).HasErrorBars = True
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).ErrorBars.Select
Selection.DELETE
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).ErrorBars.Select
ActiveChart.SeriesCollection(1).ErrorBar Direction:=xlX, Include:= _
xlPlusValues, Type:=xlFixedValue, Amount:=1
ActiveChart.SeriesCollection(1).ErrorBars.EndStyle = xlNoCap
ActiveChart.SeriesCollection(1).ErrorBar Direction:=xlX, Include:= _
xlPlusValues, Type:=xlCustom, Amount:=0
ActiveSheet.ChartObjects("Chart 1").Activate

The problem comes in with the "Selection.DELETE" command. I specifically chose 'Series "1" Y Error Bars' in the "current Selection" drop-down menu of the Excel Ribbon, then pushed the delete key, and that was the command recorded. when attempting to re-run the code, it errors on the next line after "Selection.DELETE." because all error bars (X and Y) have been deleted.

I'm wondering if there's a way to write: "ActiveChart.SeriesCollection(1).ErrorBar(Direction:=xlY).DELETE".

Again, thanks for the help!
 
Upvote 0
This "turns off" the Y error bars.

Code:
    ActiveChart.SeriesCollection(1).ErrorBar Direction:=xlY, [COLOR=#ff0000]Include:=xlNone[/COLOR], _
        Type:=xlPercent, Amount:=5
 
Upvote 0
Excellent!! That worked perfect! Sorry for the long delay in replying about the success, I have been redirected to "put out" many "fires" since I was last working on this project. Your help on this has been HUGE!!!

Now that I can edit the x-axis lines, I want to apply gradient colors to them. I can do this manually, but it's taking way too long for the scope of the project I'm working on. I've been able to change the color by:

ActiveChart.SeriesCollection(A).ErrorBars.BORDER.ColorIndex = 5

But I haven't been able to change to gradient color. With all the searching I've done I'm confident I can set the number of stops, location for the stops and color of stops, but I just cant "turn on" gradient color.

I know this chart is getting way complicated, but I'm a guy about presentation and want it to look right.

Thanks again in advance!
 
Upvote 0
I don't think you will be able to set the errorbars to show gradient color.

Have you looked at Jon Peltier's Advanced Gantt Charts. You could define gradient colors using that Ganttt chart method.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top