简体   繁体   English

Excel VBA-如何为图表系列集合选择动态范围的单元格?

[英]Excel VBA - How to select a dynamic range of cells for a chart series collection?

Im trying to define a chart series collection that goes from a determined cell to the end of data (down and right). 我试图定义一个图表系列集合,该集合从确定的单元格到数据末尾(向下和向右)。

I used the following code to set up the labels of the axis: 我使用以下代码来设置轴的标签:

oGrafico.Chart.SeriesCollection(nNoSerie).XValues = oPestana.Range(oPestana.Cells(46,14), oPestana.Cells(46,43))

I tried to use a similar approach for the data series with assignation of the ranges to the code, but the error "Application-defined or Object-defined error" pops up: 我尝试对数据系列使用类似的方法,将范围分配给代码,但是弹出错误“应用程序定义的错误或对象定义的错误”:

oGrafico.Chart.SeriesCollection(nNoSerie).Values = oPestana.Range(oPestana.Cells(47,14).End(xlToRight),oPestana.Cells(46,47).End(xlDown))

I've also tried with "oPestana.Range" instead of "oPestana.Cells" but i think i'm missing something. 我也尝试过使用“ oPestana.Range”而不是“ oPestana.Cells”,但是我想我缺少了一些东西。 Is there any way to set up the data series in a similar way? 有什么方法可以类似的方式建立数据系列吗?

这对您有用吗?

oGrafico.Chart.SeriesCollection(nNoSerie).Values = oPestana.Cells(47, 14).End(xlToRight).Resize(oPestana.Range(oPestana.Cells(46, 47), oPestana.Cells(46, 47).End(xlDown)).Cells.Count - 1, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM