excel - Do While Not IsEmpty(Range("A1")) condition evaluation failure -
i have problem code, made "load" data in create graph, 3 associated columns this:
data1 x1 y1 data2 x2 y2 data3 x3 y3
its intended behavior simple, select active cell, , enters loop: select first graph of sheet, evaluate if active cell not empty, if is, should go outside loop , end macro, if isn't, adds new series it, puts y abscissa value , puts x ordinate value, increments tracking value allows increase number of next series in graph (it initialized outside loop 1), changes row of active cell 1 below.
the problem never go outside of loop (and crashes because can't add more 256 series graph, improved code in version if condition make better, works; still adds empty series; tedious delete , may mess things if left there).
it seems condition: while not isempty(range("a1")) fails evaluate correctly. tried use while not isempty(range("a1").value) instead, or while isempty(range("a1")); while not isempty(selection) (which send error global), tried lot of other things think type of value ok, boolean, should work is. tried on new workbook new sheet , 1 line sure nothing had messed cells before , have changed state not empty program, while thought evident mistakes, still fail obtain correct behavior.
sub scatterseries() activecell.offset(0, 0).range("a1").select serie = 1 while not isempty(range("a1")) activesheet.chartobjects("chart 1").activate activechart.plotarea.select activechart.seriescollection.newseries activechart.seriescollection(serie).name = activecell activechart.seriescollection(serie).xvalues = activecell.offset(0, 2) activechart.seriescollection(serie).values = activecell.offset(0, 1) serie = serie + 1 activecell.offset(1, 0).range("a1").select loop end sub
i read few references https://www.udemy.com/blog/excel-vba-do-while/ or http://www.fontstuff.com/ebooks/free/fscodeloops.pdf fail see doing differently, cause program wrong. please give me insights that? feel stupid now. thanks.
(i must beginner vba, possible made obvious mistakes, runned actions see appear in macro, tweaked scraps of code read in examples here , there (i still plan learn language had solve problem today...:/)
isempty() used in vba check if variable has been assigned property, not check if cell blank. offset method isn't declared.
use this:
sub scatterseries() range("a1").activate serie = 1 while not activecell = "" activesheet.chartobjects("chart 1").activate activechart.plotarea.select activechart.seriescollection.newseries activechart.seriescollection(serie).name = activecell.value activechart.seriescollection(serie).xvalues = activecell.offset(0, 2).value activechart.seriescollection(serie).values = activecell.offset(0, 1).value serie = serie + 1 activecell.offset(1, 0).activate wend end sub
also, should specify .value property of range object (yes, know it's default method of range object) when testing condition on value, want sure it's looking @ value , nothing else.
Graphic Design is one of the fastest-growing and high-paying career options in the world today. If you're searching for the best graphic design course India then subhe eLearning is great platform. Learn 2D/3D Animation, VFX & graphic design in hindi from Best Industry Experts. Subhe offers a seamless experience for creating Graphics, Advertising, Photography, Image Editing for Newspapers, and much more. Become A Graphic Designer today! Apply Now
ReplyDelete