View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Programming Chart Series

1. Is the worksheet protected? I get the error you describe in this case.

2. Is the spelling of sheet "17AE" correct? Perhaps there is a space in the
name not included in the formula? I get this error in this case.

3. Note that your code sets RowNo to 43 and therefore sets the Y-values to
41 data points as implied by:
Worksheets(oSheet.Name).Range(Cells(3, Col_N), Cells(RowNo, Col_N))
Your code also sets the X-Values to 42 data points with the formula:
"='17AE'!R3C13:R42C13"
This doesn't cause me the error you describe but may for you.

4. Your code implies that your chart is an XY-Scatter. If not, it doesn't
cause me the error you describe but may for you.

Regards,
Greg



"Ken Kazinski" wrote:

Hi Greg,

Thanks for the help but I still get error 1004: Unable to set xvalues of the
series.

I copied the code but still I am getting errors. I am using excel 2003 SP1.

Thanks,

Ken


"Greg Wilson" wrote:

The following assessment was very hasty. The appended code appears to work.

Your code didn't give Col_N a value (therefore, default = 0), and, although
not essential, you didn't declare either RowNo or Col_N. Also, I believe you
intended to use oChartObj instead of oChart in the following line:
With oChart.Chart.SeriesCollection(1)
I believe the above should be:
With oChartObj.Chart.Series(1)

The expression Worksheets(oSheet.Name) returns a worksheet object. However,
you already defined the variable oSheet as refering to a worksheet. So, you
need only use oSheet in place of Worksheets(oSheet.Name).

Unqualified ranges default to the active sheet. In the following line, if
oSheet isn't the active sheet then the Cells method needs to be qualified:
Worksheets(oSheet.Name).Range(Cells(3, Col_N), Cells(RowNo, Col_N))
Using ws in place of oSheet, I believe the above should have been:
ws.Range(ws.Cells(3, Col_N), ws.Cells(RowNo, Col_N))

I substituted ws for oSheet in the below code to conserve space and
hopefully avoid workwrap.

Dim ws As Worksheet
Dim oChartObj As ChartObject
Dim RowNo As Long, Col_N As Long

Set ws = ThisWorkbook.Worksheets("Sheet1")
RowNo = 43: Col_N = 3 'change value to suit
Set oChartObj = ws.ChartObjects("Chart 1")
With oChartObj
.Top = ws.Rows(RowNo + 1).Top
.Left = ws.Columns("E").Left
.Width = ws.Columns("R").Left - ws.Columns("E").Left
.Height = ws.Rows(RowNo + 29).Top - ws.Rows(RowNo + 1).Top
With .Chart.SeriesCollection(1)
.XValues = "='17AE'!R3C13:R42C13"
.Values = ws.Range(ws.Cells(3, Col_N), ws.Cells(RowNo, Col_N))
End With
End With
End Sub

Regards,
Greg


"Ken Kazinski" wrote:

Can someone help with the code snipet below. I am trying to program a chart
series but keep getting errors.

Thanks,

Ken



Dim oSheet As Worksheet
Dim oChartObj As ChartObject
Dim Series As Series

Set oSheet = ThisWorkbook.Worksheets(WorkSheetName)
RowNo = 43

Set oChartObj = oSheet.ChartObjects("Chart 1")
With oChartObj
.Top = oSheet.Rows(RowNo + 1).Top
.Left = oSheet.Columns("E").Left
.Width = oSheet.Columns("R").Left - oSheet.Columns("E").Left
.Height = oSheet.Rows(RowNo + 29).Top - oSheet.Rows(RowNo + 1).Top
End With

' Location Reports
With oChart.Chart.SeriesCollection(1) ' "Location Reports")
.XValues = "='17AE'!R3C13:R42C13"
.Values = Worksheets(oSheet.Name).Range(Cells(3, Col_N), Cells(RowNo,
Col_N))
End With