的Excel变量范围而创建图表(Excel Variable Ranges while creati

2019-07-29 15:08发布

所以基本上我需要能够选择最后一行创建使用此方法的图表。

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列中选择最后一排。

Answer 1:

这是你想什么呢?

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


文章来源: Excel Variable Ranges while creating a chart