Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Variable Ranges while creating a chart

So basically I need to be able to select the last row to create a chart using this method.

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

I need the range for A10 to be able to select the last row in the A column.

like image 359
EbilGenius Avatar asked Mar 19 '26 01:03

EbilGenius


1 Answers

Is this what you are trying?

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
like image 54
Siddharth Rout Avatar answered Mar 20 '26 14:03

Siddharth Rout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!