从 ActiveChart.SeriesCollection(in).Points(j) / VBA / Excel / PowerPoint 引用/返回值源单元格地址
Reffering / returning value's source cell address from ActiveChart.SeriesCollection(i).Points(j) / VBA / Excel / PowerPoint
我在 Excel/PowerPoint 中有图表。在此图表中,我想从
获取每个数据点的值的源单元格地址
ActiveChart.SeriesCollection(i).Points(y)
因为 Excel 自动制作系列(这张图表不是用 VBA 制作的)所以我不会从头开始做这个参考(不是自己定义数据系列)。
我知道如何以相反的方式制作它 - 如何从精确的单元格制作 SeriesCollection.Point,但我想在现成的图表上使用它,所以不想在 [=25= 中从头开始定义图表] 再次.
感谢您的帮助!
这是 Excel 中放置在活动表中的图表的简单解决方案。代码中的注释中有一些假设和提示。
Sub GetSourceCellsAddress()
'define chart first...
Dim CH As Chart
Set CH = ActiveSheet.ChartObjects(1).Chart
'...and its first series (which is line type)
Dim SC As Series
Set SC = CH.SeriesCollection(1)
'what we need is a series formula where you find reference to the range
Dim strFormula As String
strFormula = SC.Formula
'test here:
Debug.Print strFormula 'result: =SERIES(Sheet1!$D,,Sheet1!$D:$D,1)
'but in fact we need the range with cell values, retrieve it from the formula
Dim strRangeFromFormula As String
strRangeFromFormula = Mid(strFormula, _
InStrRev(strFormula, "!") + 1, _
InStrRev(strFormula, ",") - InStrRev(strFormula, "!") - 1)
'test here
Debug.Print strRangeFromFormula 'result: $D:$D
'in fact our point PT is a range type, so, iterate through cells
Dim rngPT As Range
For Each rngPT In Range(strRangeFromFormula)
Debug.Print rngPT.Address 'results >>$D, $D, $D, $D, ....
Next rngPT
End Sub
我在 Excel/PowerPoint 中有图表。在此图表中,我想从
获取每个数据点的值的源单元格地址ActiveChart.SeriesCollection(i).Points(y)
因为 Excel 自动制作系列(这张图表不是用 VBA 制作的)所以我不会从头开始做这个参考(不是自己定义数据系列)。 我知道如何以相反的方式制作它 - 如何从精确的单元格制作 SeriesCollection.Point,但我想在现成的图表上使用它,所以不想在 [=25= 中从头开始定义图表] 再次.
感谢您的帮助!
这是 Excel 中放置在活动表中的图表的简单解决方案。代码中的注释中有一些假设和提示。
Sub GetSourceCellsAddress()
'define chart first...
Dim CH As Chart
Set CH = ActiveSheet.ChartObjects(1).Chart
'...and its first series (which is line type)
Dim SC As Series
Set SC = CH.SeriesCollection(1)
'what we need is a series formula where you find reference to the range
Dim strFormula As String
strFormula = SC.Formula
'test here:
Debug.Print strFormula 'result: =SERIES(Sheet1!$D,,Sheet1!$D:$D,1)
'but in fact we need the range with cell values, retrieve it from the formula
Dim strRangeFromFormula As String
strRangeFromFormula = Mid(strFormula, _
InStrRev(strFormula, "!") + 1, _
InStrRev(strFormula, ",") - InStrRev(strFormula, "!") - 1)
'test here
Debug.Print strRangeFromFormula 'result: $D:$D
'in fact our point PT is a range type, so, iterate through cells
Dim rngPT As Range
For Each rngPT In Range(strRangeFromFormula)
Debug.Print rngPT.Address 'results >>$D, $D, $D, $D, ....
Next rngPT
End Sub