excel - VBA Determine Series Count And Delete -
i have code creates dynamic chart using named ranges. chart should have 5 series, reason creates more this. hence determine how many series chart has, , delete series above seriescollection(5). sure way have done quite inefficient, , has broken downwards several times (due invalid parameter error). how can code task in efficient way, without need handle errors? code have used is:
with activechart if .seriescollection.count = 6 .seriescollection(6).delete end if if .seriescollection.count = 7 .seriescollection(6).delete .seriescollection(7).delete end if if .seriescollection.count = 8 .seriescollection(6).delete .seriescollection(7).delete .seriescollection(8).delete end if end
looking after these lines:
if .seriescollection.count = 7 you delete seriescollection(6) executes fine. but, way collections work sequentially, seriescollection(7) gets shifted downwards (6) spot. then, when go delete (7) it's not there anymore , error. seek this:
if .seriescollection.count = 7 .seriescollection(7).delete .seriescollection(6).delete end if if .seriescollection.count = 8 .seriescollection(8).delete .seriescollection(7).delete .seriescollection(6).delete end if let know if works.
excel vba charts series
No comments:
Post a Comment