Using the code in my VBA macro:
Charts.Add
ActiveChart.ChartType = xlBubble
The macro hangs at the second line and I get the error:
Run-time error '1004':
Method 'ChartType' of object '_Chart' failed.
Has anyone else had this same problem? Why won't the
bubble chart work?
Thanks,
Tim
The macro recorder doesn't always create code that works efficiently, and
sometimes the code doesn't work at all. The bubble chart is one of these
cases.
You probably have an ActiveChart.SetSourceData statement in your code. Put
this line above the ActiveChart.ChartType = xlBubble, and you will get your
bubble chart. Make sure the SetSourceData includes a range with three
columns, X, Y, and bubblesize, or else it will hang anyway.
The following makes a bubble chart on the active sheet using data in the
seected range.
Sub RegularBubbleChart()
Dim oChart As ChartObject
Dim rngData As Range
Set rngData = Selection
Set oChart = ActiveSheet.ChartObjects.Add(100, 100, 350, 225)
With oChart.Chart
.SetSourceData Source:=rngData
.ChartType = xlBubble
End With
End Sub
- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______
In article <548b01c2bcec$7b0564d0$d5f82ecf@TK2MSFTNGXA12>,
tim.o...@twdb.state.tx.us says...
Does anyone have any more suggestions?? Frustrating.
Tim
>.
>
Jon's example code worked for me (using XL2000, WK2000).
Have you tried it?
Did you have a valid range of cells selected when you ran it?
Tim wrote:
> >.
> >
--
Cheers
Andy
Tim
>.
>
Shouldn't need any special paks.
If you want to email the workbook I can take a look.
Use this account andy_...@yahoo.co.uk as I am not work.
Please don't attach anything back to the NG.
Cheers
Andy
Located the problem.
In the code where you go to create the chart the range E3:G200, although
it contains cell formula's is sparsely populated with data. For some
reason the chart tries to interpert you requirements and makes a real
has of it. Try manually selecting the range, after completion use
E9:G200, and use the chart wizard. even with the column chart if you
"Press and Hold to view" you will see the chart has no data points.
That in itself is not a problem when it creates it BUT when you try and
make it a Bubble the code blows up.
Without spending a great deal of time on the detail of your code, my
solution was to reduce the data range to valid cell content. This was
done purely by looking at the cells when it originally fails.
Note subsequent data may cause the problem to happen again.
slot the following code snip into your existing code. Watch out for word
wrap.
'---
'
' Start Bubble Chart Here!!!
'
Range("E3:G200").Select
Range("E3").Activate
'Set oChart = ActiveSheet.ChartObjects.Add(100, 100, 350, 225)
'With oChart.Chart
' .SetSourceData Source:=Sheets("x").Range("E3:G200"), PlotBy:= _
' xlColumns
' .ChartType = xlBubble
'End With
Charts.Add
' revised line
ActiveChart.SetSourceData Source:=Sheets("x").Range("E3:G6"),
PlotBy:= _
xlColumns
ActiveChart.ChartType = xlBubble
ActiveChart.SetSourceData Source:=Sheets("x").Range("E3:G200"),
PlotBy:= _
xlBubble
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=x!R3C6:R200C6"
'----
An problems post back.
Cheers
Andy
Tim
>.
>
=IF(<something>,A10,"")
The zero length strings ("") which look like blanks caused the problem. If
they had been real blank cells, the chart would have worked, or if the
formulas looked like this instead:
=IF(<something>,A10,NA())
the #N/A errors would have worked fine in the chart. I tried the above type
of formula, and the bubble chart was built properly.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______
In article <OPYzlxavCHA.848@TK2MSFTNGP11>, an...@digitab.demon.co.uk says...