excel vba - draw more than one plot using vba -
i trying draw more 1 plot using vba in excel wrote code enable me draw 1 drawing
sub trial() activesheet.shapes.addchart2(240, xlxyscattersmoothnomarkers).select activechart.seriescollection.newseries activechart.haslegend = true activechart.fullseriescollection(1).name = "=""hbes""" activechart.fullseriescollection(1).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(1).values = "=en!$dp$253:$dp$257" activechart.seriescollection.newseries activechart.fullseriescollection(2).name = "=""nhbes""" activechart.fullseriescollection(2).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(2).values = "='en1'!$do$253:$do$257" activechart.seriescollection.newseries activechart.fullseriescollection(3).name = "=""nhbcs""" activechart.fullseriescollection(3).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(3).values = "=en1c!$do$253:$do$257" activechart.seriescollection.newseries activechart.fullseriescollection(4).name = "=""hbcs""" activechart.fullseriescollection(4).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(4).values = "=enc!$dp$253:$dp$257" activechart 'chart name .hastitle = true .charttitle.characters.text = "expected number of goods group twenty in condition state five" 'x axis name .axes(xlcategory, xlprimary).hastitle = true .axes(xlcategory, xlprimary).axistitle.characters.text = "time (years)" 'y-axis name .axes(xlvalue, xlprimary).hastitle = true .axes(xlvalue, xlprimary).axistitle.characters.text = "expected number of goods" end end sub what need make data range variable tried adjust above code in following manner
sub trial() activesheet.shapes.addchart2(240, xlxyscattersmoothnomarkers).select activechart.seriescollection.newseries activechart.haslegend = true activechart.fullseriescollection(1).name = "=""hbes""" activechart.fullseriescollection(1).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(1).values = sheets("sheets12").range(cells(253,32),cells(302,32)) activechart.seriescollection.newseries activechart.fullseriescollection(2).name = "=""nhbes""" activechart.fullseriescollection(2).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(2).values = sheets("sheets13").range(cells(253,32),cells(302,32)) activechart.seriescollection.newseries activechart.fullseriescollection(3).name = "=""nhbcs""" activechart.fullseriescollection(3).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(3).values = sheets("sheets14").range(cells(253,32),cells(302,32)) activechart.seriescollection.newseries activechart.fullseriescollection(4).name = "=""hbcs""" activechart.fullseriescollection(4).xvalues = "=en!$g$253:$g$257" activechart.fullseriescollection(4).values = sheets("sheets15").range(cells(253,32),cells(302,32)) activechart 'chart name .hastitle = true .charttitle.characters.text = "expected number of goods group twenty in condition state five" 'x axis name .axes(xlcategory, xlprimary).hastitle = true .axes(xlcategory, xlprimary).axistitle.characters.text = "time (years)" 'y-axis name .axes(xlvalue, xlprimary).hastitle = true .axes(xlvalue, xlprimary).axistitle.characters.text = "expected number of goods" end end sub but doesn't work suggestion please?
thanks in advance
looking @ first series you're trying add. in first snippet you're trying pull data range dp253:dp257, columnindex column dp 120, not 32 cells(253, 32) refers cell af253 , cells(302, 32) refers cell af302.
for plot named "hbes"
.values = sheets("en").range(cells(253, 120), cells(257, 120)) edit
for plot named "nhbes"
.values = sheets("'en1'").range(cells(253, 119), cells(257, 119)) for plot named "nhbcs"
.values = sheets("en1c").range(cells(253, 119), cells(257, 119)) for plot named "hbcs"
.values = sheets("enc").range(cells(253, 120), cells(257, 120)) the code built follows
sheets("name of sheet appears on tab in workbook").range(cells(rownumber of top (left) cell in range, columnnumber of top (left) cell in range), cells(rownumber of bottom (right) cell in range, columnumber of bottom right cell in range)) if referring range a1:b5, you'd type range(cells(1, 1), cells(5, 2)
Comments
Post a Comment