tmatematikas
10-18-2008, 01:42 PM
Hello, I was writing some interesting code for adding multiple charts to single worksheet. The code above works fine if I place all charts into separate sheets (.Location Where:=xlLocationAsNewSheet), but I get errors with (.Location Where:=xlLocationAsObject, Name:=sheetTitle):
Public Function Chart(penketas As Integer, turis As Integer)
sheetTitle = "charts"
'Dim chtChart As Chart 'tried also
'Set chtChart = Charts.Add
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("1-" & turis & "-freq").Range("B3:B12").Offset(0, 2 * (penketas - 1)), PlotBy:=xlColumns
.SeriesCollection(1).XValues = "='1-" & turis & "-freq'!" & "R3C" & (2 * penketas - 1) & ":R12C" & (2 * penketas - 1)
'.Location Where:=xlLocationAsNewSheet
.Location Where:=xlLocationAsObject, Name:=sheetTitle
.ChartTitle.Characters.Text = "Sumos pasiskirstymo histogram after " & (5 * penketas) & " year"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Start point"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Freq"
.HasLegend = False
.HasDataTable = False
End With
End Function
Where is the mistake? Maybe some kind of type mismatch? When I comment everything starting .ChartTitle and ending .HasDataTable the code works :dunno.
Public Function Chart(penketas As Integer, turis As Integer)
sheetTitle = "charts"
'Dim chtChart As Chart 'tried also
'Set chtChart = Charts.Add
Charts.Add
With ActiveChart
.ChartType = xlColumnClustered
.SetSourceData Source:=Sheets("1-" & turis & "-freq").Range("B3:B12").Offset(0, 2 * (penketas - 1)), PlotBy:=xlColumns
.SeriesCollection(1).XValues = "='1-" & turis & "-freq'!" & "R3C" & (2 * penketas - 1) & ":R12C" & (2 * penketas - 1)
'.Location Where:=xlLocationAsNewSheet
.Location Where:=xlLocationAsObject, Name:=sheetTitle
.ChartTitle.Characters.Text = "Sumos pasiskirstymo histogram after " & (5 * penketas) & " year"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Start point"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Freq"
.HasLegend = False
.HasDataTable = False
End With
End Function
Where is the mistake? Maybe some kind of type mismatch? When I comment everything starting .ChartTitle and ending .HasDataTable the code works :dunno.