2016-07-22 160 views

回答

0

您可以使用TopLeftCellBottomRightCell找出給定的範圍之間的圖表。

Sub testChart() 
Dim oChart As Chart 

'/ Selecet the chart , if found in Range D4:F10 
Set oChart = findChart(Sheet1.Range("D4:F10")) 
If Not oChart Is Nothing Then 
    oChart.Parent.Select 
Else 
    MsgBox "No chart found." 
End If 

End Sub 

Function findChart(ByVal rngChart As Range) As Chart 

    Dim oChart  As Chart 
    Dim oChartObj As ChartObject 
    Dim wksChart As Worksheet 
    Dim rngCArea As Range 

    Set wksChart = rngChart.Parent 

    For Each oChartObj In wksChart.ChartObjects 
     Set rngCArea = Intersect(wksChart.Range(rngChart.Address), wksChart.Range(oChartObj.TopLeftCell, oChartObj.BottomRightCell)) 
     If Not rngCArea Is Nothing Then 
      Set oChart = oChartObj.Chart 
     End If 
    Next 

    Set findChart = oChart 

End Function 
+0

如果這個解決方案的工程,然後將其標記爲回答:http://stackoverflow.com/help/someone-answers,http://meta.stackexchange.com/questions/173399/how-to-upvote-堆棧上溢 – cyboashu

相關問題