Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 1
Default Dynamic chart generation: Run time Error '1004: Method 'Cells' of object'_Global' fai


--------------------------------------------------------------------------------

Hello,

I am trying to generate a chart with multiple series. The number of
series is not fixed and can be any number. I recorded a macro and then
modified the code. 'Counter' refers to the number of the series and i
have referenced it in a worksheet. I am getting the error in the line
that is bold. Thank you for your help.

The code is as follows:

Dim Counter As Integer
Dim i As Integer

Sheets("With TC").Select
Counter = Cells(38, 13).Value
ActiveChart.ChartType = xlLine
With Sheets("VP_WithTC")
ActiveChart.SetSourceData Source:=.Range(.Cells(2, 13), .Cells(Counter,
16)), PlotBy _
:=xlRows
End With
For i = 2 To Counter
With ActiveChart.SeriesCollection.NewSeries

.VALUES = ACTIVESHEET.RANGE(CELLS(I, 13), CELLS(I, 16))
.XValues = ActiveSheet.Range("E1:H1")
End With

Next i

ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Value Path Graph"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Criteria"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Normalized
values"
End With


End Sub


--
Ajay_N
------------------------------------------------------------------------
Ajay_N's Profile: http://www.excelforum.com/member.php...o&userid=37418
View this thread: http://www.excelforum.com/showthread...hreadid=571032

  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Dynamic chart generation: Run time Error '1004: Method 'Cells' of object'_Global' fai

If your active chart is a chart sheet, then the active sheet is the chart,
not a worksheet. So ActiveSheet.Cells will break.

You could add the chart directly as an embedded chart object, thus keeping
the workbook as the active sheet. Even if the chart is active, you can
reference the cells on the worksheet below.

The syntax is

ActiveSheet.ChartObjects.Add(left, top, width, height)

The dimensions in parentheses are for the embedded chart object, in points.

More VBA charting tips:

http://peltiertech.com/Excel/ChartsH...kChartVBA.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Ajay_N" wrote in
message ...

--------------------------------------------------------------------------------

Hello,

I am trying to generate a chart with multiple series. The number of
series is not fixed and can be any number. I recorded a macro and then
modified the code. 'Counter' refers to the number of the series and i
have referenced it in a worksheet. I am getting the error in the line
that is bold. Thank you for your help.

The code is as follows:

Dim Counter As Integer
Dim i As Integer

Sheets("With TC").Select
Counter = Cells(38, 13).Value
ActiveChart.ChartType = xlLine
With Sheets("VP_WithTC")
ActiveChart.SetSourceData Source:=.Range(.Cells(2, 13), .Cells(Counter,
16)), PlotBy _
:=xlRows
End With
For i = 2 To Counter
With ActiveChart.SeriesCollection.NewSeries

VALUES = ACTIVESHEET.RANGE(CELLS(I, 13), CELLS(I, 16))
XValues = ActiveSheet.Range("E1:H1")
End With

Next i

ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
HasTitle = True
ChartTitle.Characters.Text = "Value Path Graph"
Axes(xlCategory, xlPrimary).HasTitle = True
Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Criteria"
Axes(xlValue, xlPrimary).HasTitle = True
Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Normalized
values"
End With


End Sub


--
Ajay_N
------------------------------------------------------------------------
Ajay_N's Profile:
http://www.excelforum.com/member.php...o&userid=37418
View this thread: http://www.excelforum.com/showthread...hreadid=571032



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic end on chart Donna YaWanna Charts and Charting in Excel 1 June 17th 05 04:50 PM
Timeline Chart? ckrogers Charts and Charting in Excel 3 March 17th 05 09:20 PM
Strange Problem with Chart and Plot Visible Cells Option Marcus Leon Charts and Charting in Excel 1 January 7th 05 03:52 AM
Convert data type of cells to Text,Number,Date and Time Kevin Excel Worksheet Functions 1 December 31st 04 12:57 PM
Chart disappears when source data cells are hidden Disappearing charts Excel Discussion (Misc queries) 2 December 5th 04 03:24 AM


All times are GMT +1. The time now is 09:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"