excel - VBA code only working for some charts -


my vba code updating secondary axes range on graphs of worksheet works of graphs. after macro run, message "method 'axes' of object '_chart' failed" displayed, of graphs on worksheet being updated. what's problem here?

sub macro1()  dim objchart chartobject, lower double, upper double  lower = application.inputbox(prompt:="enter lower bound", type:=1) upper = application.inputbox(prompt:="enter upper bound", type:=1)  each objchart in sheets("summary").chartobjects     objchart.chart.axes(xlvalue, xlsecondary)         .minimumscale = lower         .maximumscale = upper     end next objchart  end sub 

if chartobject doesn't have secondary axis, accessing raise error. couldn't figure out way reproduce exact error, said in a comment, extracting procedure , handling runtime errors should @ least diagnosing problem , making loop iterate charts:

public sub updatesummarysheetchartaxes()      dim lower double     lower = application.inputbox(prompt:="enter lower bound", type:=1)      dim upper double             upper = application.inputbox(prompt:="enter upper bound", type:=1)      dim objchart chartobject     each objchart in sheets("summary").chartobjects         updatechartaxes objchart, lower, upper     next objchart  end sub  private sub updatechartaxes(byval objchart chartobject, byval lower double, byval upper double)     on error goto cleanfail     objchart.chart.axes(xlvalue, xlsecondary)         .minimumscale = lower         .maximumscale = upper     end cleanexit:     exit sub cleanfail:     debug.print "failed updating axes chart '" & objchart.name & "'. message: " & err.description     resume cleanexit end sub 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -