View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta Tushar Mehta is offline
external usenet poster
 
Posts: 1,071
Default How to make chart embedded in active sheet?

Thin lines in a bar chart is a sign that there are many data points (or
data points far apart for a time-scale x-axis. Check what range XL
plotted, the x-values, and what kind of x-axis XL created.

To deal with the location issue, you are on the right track. When you
move the move the chart from its own sheet to a worksheet, the object
the variable objChart pointed to no longer exists and you get errors on
subsequent statements. However, that does not mean you have to rely on
'ActiveChart' for further work. Instead use objChart with

Set objChart = Charts.Add.Location( _
xlLocationAsObject, strSheetName)
with objChart
...


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
OK, this works:

Set objChart = Charts.Add

With objChart
.Location xlLocationAsObject, strSheetName
End With

With ActiveChart
.SetSourceData _
Source:=rngRange, _
PlotBy:=xlColumns
.ChartType = xlColumnClustered
.HasTitle = True
.ChartTitle.Characters.Text = strName
.HasLegend = False
End With

Understand now that the second argument of .Location has to be an existing
sheet.

Now the strange thing is that this works fine in my first range, but if I
run the same
on a different range I get no proper columns anymore, but very thin lines,
although it is
still the column type of chart. This other range has the same kind of data
as the first range.

RBS


"RB Smissaert" wrote in message
...
When I record making a chart embedded in the sheet I get this:

Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("testsheet"). _
Range("J3:K14"), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:= _
"testsheet"

But this doesn't work as it falls over at the line where the location is
set:

Set objChart = Charts.Add

With objChart
.Location xlLocationAsObject, strName
.ChartType = xlColumnClustered
.SetSourceData _
Source:=rngRange, _
PlotBy:=xlColumns
End With

The error will be:
runtime error 1004, method location of object chart failed.
A chart has already been made, but not this is a chart in a new chartsheet
and I don't want that.
How should this be done?


RBS