Something weird with Stock chart in excel -


i have vba code in excel automatically creates agraph , format , paste in chart excel sheet. code seems work fine graphs except stock graph. whenever run macro, can see chart creation when comes formatting , specially pasting, graph becomes invisibel. in other words, cant see graph when code finishes running.

i dont know going on stock graph? can explain , tell me solution fix it? lot.

here code:

sub creategraph() dim myrng range dim lastcell long lastcell = worksheets(1).range("e3").end(xldown).row set myrng = worksheets(1).range("b3:e" & lastcell)     activesheet.shapes.addchart.select     activechart.setsourcedata source:=myrng     activechart.charttype = xlstockhlc     activechart.location where:=xllocationasobject, name:="chart1" end sub  sub formatchart() let title = sheets("sheet1").cells(2, 1)     activesheet.chartobjects("chart 1").activate     activechart.seriescollection(1).select     activesheet.chartobjects("chart 1").activate     activechart.axes(xlcategory).select     activechart.axes(xlcategory).reverseplotorder = true     activesheet.chartobjects("chart 1").activate     activechart.setelement (msoelementcharttitleabovechart)     activechart.charttitle.select     activesheet.chartobjects("chart 1").activate     activechart.charttitle.text = title & "responses*"     activechart.charttitle.font     .name = "arial"     .fontstyle = "bold"     .size = 8     end     activechart.axes(xlcategory).ticklabels.font     .name = "arial"     .fontstyle = "regular"     .size = 7     end     activechart.axes(xlvalue).ticklabels.font     .name = "arial"     .fontstyle = "regular"     .size = 7     end     activechart.plotarea.interior     .colorindex = 2     .patterncolorindex = 1     .pattern = xlsolid     end     range("s4").select     activewindow.smallscroll down:=48     activesheet.chartobjects("chart 1").activate     activechart.legend.select     activechart.legend.font     .name = "arial"     .fontstyle = "regular"     .size = 8     end     activewindow.smallscroll down:=45     activesheet.chartobjects("chart 1").activate     activechart.plotarea.select     activesheet.chartobjects("chart 1").activate     activewindow.smallscroll down:=-45     activesheet.chartobjects("chart 1").activate     activechart.axes(xlvalue).majorgridlines.select     activesheet.chartobjects("chart 1").activate     activewindow.smallscroll down:=-54     activesheet.chartobjects("chart 1").activate     activechart.chartarea.select     activechart.chartarea.width = 500     activechart.chartarea.height = 1000     activesheet.chartobjects("chart 1").activate     activesheet.chartobjects("chart 1").activate     activechart.axes(xlvalue).majorgridlines.select     activesheet.chartobjects("chart 1").activate     activesheet.chartobjects("chart 1").activate     activesheet.chartobjects("chart 1").activate     activesheet.chartobjects("chart 1").activate     activesheet.chartobjects("chart 1").activate     activechart.axes(xlvalue).select     activesheet.chartobjects("chart 1").activate     activechart.axes(xlvalue).majorgridlines.select     activesheet.chartobjects("chart 1").activate     activesheet.chartobjects("chart 1").activate     activechart.axes(xlvalue).select     activechart.axes(xlvalue).minimumscale = 0     activechart.axes(xlvalue).maximumscale = 100     activechart.axes(xlvalue).majorunit = 20     activechart.axes(xlvalue).majorunit = 10         activechart.seriescollection(1)         .interior.color = rgb(0, 51, 153)     end             activechart.seriescollection(2)         .interior.color = rgb(80, 116, 77)     end         activesheet.chartobjects("chart 1").activate         activesheet.chartobjects("chart 1").activate     selection.cut     sheets("chart2").select     activechart.paste end sub 

nupur,

try (tried , tested)

replace code

activesheet.chartobjects("chart 7").activate activesheet.chartobjects("chart 7").activate selection.cut sheets("chart2").select activechart.paste 

with

activesheet.chartobjects("chart 7").activate activechart.location where:=xllocationasobject, name:="chart2" 

suggestion: believe recorded macro? :) 2 piece of code same thing :) excel ways pretty 'humble' need tell once ;)

activesheet.chartobjects("chart 1").activate activesheet.chartobjects("chart 1").activate activesheet.chartobjects("chart 1").activate activesheet.chartobjects("chart 1").activate activesheet.chartobjects("chart 1").activate 

and this

activesheet.chartobjects("chart 1").activate 

you can safely delete lines.

hth

sid


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -