close

I am writing a macro that includes assigning x-values from the third column
of Sheet 1 to the active chart:

ActiveChart.SeriesCollection(1).XValues = Sheets(quot;Sheet1quot;).Range(quot;C2:C105quot;)

However, when I change the range-referencing to cells-style, I get an error:

ActiveChart.SeriesCollection(1).XValues =
Sheets(quot;Sheet1quot;).Range(Cells(1,3),Cells(105,3))

The error says: quot;Method of 'Cells' of object '_Global' failed

Does the XValues argument not take Cells-style referencing? I ask because
what I really want to do is assign a variable to the range that changes
according to the number of rows in the column that contain data:

ActiveChart.SeriesCollection(1).XValues =
Sheets(quot;Sheet1quot;).Range(Cells(1,3),Cells(num_rows,3 ))

You need to reference the cells:

ActiveChart.SeriesCollection(1).XValues = _
Sheets(quot;Sheet1quot;).Range(Sheets(quot;Sheet1quot;).Cells(1,3) ,
Sheets(quot;Sheet1quot;).Cells(105,3))

or

With Sheets(quot;Sheet1quot;).
ActiveChart.SeriesCollection(1).XValues = .Range(.Cells(1,3),
..Cells(105,3))
End With

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
PeltierTech.com/
_______quot;JF_01quot; gt; wrote in message
...
gt;I am writing a macro that includes assigning x-values from the third column
gt; of Sheet 1 to the active chart:
gt;
gt; ActiveChart.SeriesCollection(1).XValues =
gt; Sheets(quot;Sheet1quot;).Range(quot;C2:C105quot;)
gt;
gt; However, when I change the range-referencing to cells-style, I get an
gt; error:
gt;
gt; ActiveChart.SeriesCollection(1).XValues =
gt; Sheets(quot;Sheet1quot;).Range(Cells(1,3),Cells(105,3))
gt;
gt; The error says: quot;Method of 'Cells' of object '_Global' failed
gt;
gt; Does the XValues argument not take Cells-style referencing? I ask because
gt; what I really want to do is assign a variable to the range that changes
gt; according to the number of rows in the column that contain data:
gt;
gt; ActiveChart.SeriesCollection(1).XValues =
gt; Sheets(quot;Sheet1quot;).Range(Cells(1,3),Cells(num_rows,3 ))

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()