Error when create chartobject on line ".HasTitle = True"

T

tskogstrom

Hi,

I gett runtime 1004 at line "HasTitle = True"
The peculiar thing is that yesterday it worked ok. I saved it, slept,
and now I get the error. I have tested to put the Has title ocde in the
end of the sub, after seriescollections etc, but with same results.
Any ideas, anybody?

/Kind regards
tskogstrom


Sub CreateChartCF()
Dim cht As Chart

Dim chtTitle As String
chtTitle = "CashFlow & PayBack"

On Error Resume Next '(if no chartobject)
Sheet2.ChartObjects("R_CF").Delete
On Error GoTo 0

If Sheet1.Range("Years").Value > 1 Then

With Sheet2.ChartObjects.Add(Range("RAPP_BASE_CHT_CF").Left, _
Range("RAPP_BASE_CHT_CF").Top, 468, 260)
.Name = "R_CF"
End With

Set cht = Sheet2.ChartObjects("R_CF").Chart
With cht
.ChartType = xlColumnClustered
.SetSourceData Sheet10.Range("CHT_CFSOURCE_" &
Sheet2.Range("RAPP_TILLF").Value), _
PlotBy:=xlRows
.HasTitle = True
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
.ChartTitle.Characters.Text = chtTitle
End With

With cht.SeriesCollection(1)
.Fill.OneColorGradient Style:=msoGradientVertical,
Variant:=4, _
Degree:=0.25
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 47
End With

With cht.SeriesCollection(2)
.Fill.OneColorGradient Style:=msoGradientVertical,
Variant:=4, _
Degree:=0.25
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 45
End With

....etc etc
 
T

tskogstrom

It seems that if the source is hidden rows or columns, I get the error
!! Is this really correct?
Is there any workarounds in code, or do I need to create a new sheet
with linked sourceranges? That would be some trouble to me ...

/Regards
tskogstrom


tskogstrom skrev:
 
A

Andy Pope

Hi,

If your chart contains no data then either manually or with code you
will not be able to set the chart title.
If you need a chart title even when no data is present you could add a
dummy series.

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top