2012-05-29 55 views
3

所以基本上我需要能夠選擇最後一行來使用此方法創建圖表。創建圖表時Excel變量範圍

Sub createchart2() 
    lastA = Range("A1").End(xlDown).Row 
    ActiveSheet.Shapes.AddChart.Select 
    ActiveChart.ChartType = xlLine 
    ActiveChart.SetSourceData Source:=Range("Main!$A$3:$A$10") 
End Sub 

我需要範圍A10能夠選擇A列中的最後一行。

回答

3

這是你正在嘗試?

Sub createchart2() 
    Dim lastA As Long 

    lastA = Range("A" & Rows.Count).End(xlUp).Row 

    ActiveSheet.Shapes.AddChart.Select 
    ActiveChart.ChartType = xlLine 

    ActiveChart.SetSourceData Source:=Range("Main!$A$3:$A$" & lastA) 
End Sub 
+0

謝謝悉達思,它的工作,我一直在這一整晚的工作x) – EbilGenius