T
tskogstrom
Hi,
Can anybody find what is wrong with this code? It will just make a
empty chartobject. I believe the ranges are ok, it probably is some bad
syntax or object reference...
The code should make a chart with two series of xlColumnClustered and
one serie of xlLineMarkers.
Thank you
/tskogstrom
---------------------------------------
CODE:
Sub UppdateChartCF()
Dim cht As Chart
Set cht = Sheet1.ChartObjects("R_CF").Chart
On Error Resume Next '(if no chartobject)
Sheet1.ChartObjects("R_CF").Delete
On Error GoTo EndCode
'Left and Top location = named ranges
With Sheet1.ChartObjects.Add(Range("RAPP_BASE_CHT_CF").Left, _
Range("RAPP_BASE_CHT_CF").Top, 468, 260)
.Name = "R_CF"
End With
With cht
.SetSourceData Sheet2.Range("CHT_CF_RNG"), PlotBy = xlRows
.HasTitle = True
.ChartTitle.Characters.Text = "Some Title text"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With cht.SeriesCollection.NewSeries
.Name = Sheet2.Range("CHT_R_INVEST")
.Values = Sheet2.Range("CHT_" &
Sheet1.Range("SCENARIO_NO").Value & "CF" & _
Sheet1.Range("RAPP_TILLF").Value & "_INVESTAR")
.ChartType = xlColumnClustered
.Fill.TwoColorGradient Style:=msoGradientVertical, Variant:=3
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 3
.Fill.BackColor.SchemeColor = 2
End With
With cht.SeriesCollection.NewSeries
.Name = Sheet2.Range("CHT_R_EFF")
.Values = Sheet2.Range("CHT_" &
Sheet1.Range("SCENARIO_NO").Value & "CF" & _
Sheet1.Range("RAPP_TILLF").Value & "_EFFEKTAR")
.ChartType = xlColumnClustered
.Fill.TwoColorGradient Style:=msoGradientDiagonalUp, Variant:=3
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 58
.Fill.BackColor.SchemeColor = 34
End With
With cht.SeriesCollection.NewSeries
.Values = Sheet2.Range("CHT_" &
Sheet1.Range("SCENARIO_NO").Value & "CF" & _
Sheet1.Range("RAPP_TILLF").Value & "_PAYBACK")
.Name = Sheet2.Range("CHT_R_PAYBACK")
.ChartType = xlLineMarkers
End With
Sheet1.DrawingObjects("R_CF").RoundedCorners = True
'Format Border
With cht.ChartArea.Border
.ColorIndex = 37
.Weight = 1
.LineStyle = 1
End With
Sheet1.DrawingObjects("R_CF").RoundedCorners = True
EndCode:
On Error GoTo 0
End Sub
Can anybody find what is wrong with this code? It will just make a
empty chartobject. I believe the ranges are ok, it probably is some bad
syntax or object reference...
The code should make a chart with two series of xlColumnClustered and
one serie of xlLineMarkers.
Thank you
/tskogstrom
---------------------------------------
CODE:
Sub UppdateChartCF()
Dim cht As Chart
Set cht = Sheet1.ChartObjects("R_CF").Chart
On Error Resume Next '(if no chartobject)
Sheet1.ChartObjects("R_CF").Delete
On Error GoTo EndCode
'Left and Top location = named ranges
With Sheet1.ChartObjects.Add(Range("RAPP_BASE_CHT_CF").Left, _
Range("RAPP_BASE_CHT_CF").Top, 468, 260)
.Name = "R_CF"
End With
With cht
.SetSourceData Sheet2.Range("CHT_CF_RNG"), PlotBy = xlRows
.HasTitle = True
.ChartTitle.Characters.Text = "Some Title text"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With cht.SeriesCollection.NewSeries
.Name = Sheet2.Range("CHT_R_INVEST")
.Values = Sheet2.Range("CHT_" &
Sheet1.Range("SCENARIO_NO").Value & "CF" & _
Sheet1.Range("RAPP_TILLF").Value & "_INVESTAR")
.ChartType = xlColumnClustered
.Fill.TwoColorGradient Style:=msoGradientVertical, Variant:=3
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 3
.Fill.BackColor.SchemeColor = 2
End With
With cht.SeriesCollection.NewSeries
.Name = Sheet2.Range("CHT_R_EFF")
.Values = Sheet2.Range("CHT_" &
Sheet1.Range("SCENARIO_NO").Value & "CF" & _
Sheet1.Range("RAPP_TILLF").Value & "_EFFEKTAR")
.ChartType = xlColumnClustered
.Fill.TwoColorGradient Style:=msoGradientDiagonalUp, Variant:=3
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 58
.Fill.BackColor.SchemeColor = 34
End With
With cht.SeriesCollection.NewSeries
.Values = Sheet2.Range("CHT_" &
Sheet1.Range("SCENARIO_NO").Value & "CF" & _
Sheet1.Range("RAPP_TILLF").Value & "_PAYBACK")
.Name = Sheet2.Range("CHT_R_PAYBACK")
.ChartType = xlLineMarkers
End With
Sheet1.DrawingObjects("R_CF").RoundedCorners = True
'Format Border
With cht.ChartArea.Border
.ColorIndex = 37
.Weight = 1
.LineStyle = 1
End With
Sheet1.DrawingObjects("R_CF").RoundedCorners = True
EndCode:
On Error GoTo 0
End Sub