Excel VBA Charts -> range select using "Cells" in within Charts -
i'm trying modify existing vba code (excel) makes chart graphs, , make more flexible.
i know following pieces of code same thing:
range(cells(12, 2), cells(15, 2)).select
is more or less identical to:
range("b12:b15").select
my goal have graph, representing flexible count of rows.
so have changed existing code:
activechart.setsourcedata source:=sheets("log-data").range("b12:b200"), plotby:=xlcolumns
to
dim lastrow 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 execute code, receive:
run-time error '1004': application-defined or object-defined error
the lastrow
variable not problem: have same result if replace 200.
what doing wrong?
cheers
peter
lastrow = activesheet.usedrange.rows(activesheet.usedrange.rows.count).row
and
lastrow = activesheet.usedrange.rows.count
are same.
as far actual error goes, looks if have no active chart object when code run. activechart.
returns object error.
try this:
dim lastrow integer lastrow = activesheet.usedrange.rows.count activesheet.shapes.addchart.select activechart.setsourcedata source:=sheets("log-data").range(cells(12, 2), cells(lastrow, 2)), plotby:=xlcolumns
Comments
Post a Comment