excel vba - Accessing PivotChart SeriesCollection with a Sub -
i quite new vba. have written macro creates 10 pivot charts , normal charts after filtering , cutting data database spreadsheet. want write sub goes through applying same formatting each one. sub follows:
sub formatchart(cht chartobject, title string) cht.activate msgbox activechart.seriescollection.count activechart .hastitle = true .charttitle.text = title .axes(xlvalue).hasmajorgridlines = false end activechart.seriescollection(1).select selection.format.fill .visible = msotrue .forecolor.rgb = rgb(255, 182, 0) end end sub i didn't include activates , selects, couldn't macro work without them , don't see end of world - datasets never going massive speed isn't of concern, , disable screenupdating users can't click on cells/other objects , disrupt macro runs.
here's problem. if take out second loop, proceeds , gridlines removed , title added. however, whenever try edit colours of columns above run time error '1004': invalid parameter. i've tried keeping content of second loop inside first moved out try using selection see if made difference.
i've fiddled around quite bit , recorded various macros changing colour of chart in question, think problem might referencing seriescollection when try debug
msgbox activechart.seriescollection.count i "0".
please let me know if i'm missing point - said new vba , trying learn as possible :)
edit: solution was passing each chart above sub after had created chart, before had set data source chart. doh!
this meant there no seriescollections chart, hence error getting.
i marked joehannah answering question (even though isn't technically solution) because made me check code , notice above causing problem - if shouldn't please tell me , i'll try fix it!
you better off using set cht = (create chart object) each chart , calling format method passing in cht.
Comments
Post a Comment