I'm trying to modify an existing VBA code (Excel) which makes Chart graphs, and make it more flexible.
I know that the following pieces of code do basically the same thing:
Range(Cells(12, 2), Cells(15, 2)).Select
is more or less identical to:
Range("B12:B15").Select
My goal was to have a Graph, which is representing the flexible count of rows.
So I have changed the existing code:
ActiveChart.SetSourceData Source:=Sheets("Log-Data").Range("B12:B200"), PlotBy:=xlColumns
to
Dim LastRow As Integer
LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
ActiveChart.SetSourceData Source:=Sheets("Log-Data").Range(Cells(12, 2), Cells(LastRow, 2)), PlotBy:=xlColumns
Now, whenever I execute the code, I receive:
Run-time error '1004': Application-defined or object-defined error
The LastRow
variable is not the problem: I have the same result if I replace it with 200.
What am I doing wrong?
Cheers
Peter