vba - Excel Visual Basic Macro- Selecting data dynamically for a chart? -
so, question stupid, i'm not familiar excel vba. here's generated macro code imports data text file , graphs it.
sub getdata() ' ' getdata macro ' ' activesheet.querytables.add(connection:= _ "text;c:\data.txt", destination:=range("$d$3")) .name = "data_2" .fieldnames = true .rownumbers = false .filladjacentformulas = false .preserveformatting = true .refreshonfileopen = false .refreshstyle = xlinsertdeletecells .savepassword = false .savedata = true .adjustcolumnwidth = true .refreshperiod = 0 .textfilepromptonrefresh = false .textfileplatform = 437 .textfilestartrow = 1 .textfileparsetype = xldelimited .textfiletextqualifier = xltextqualifierdoublequote .textfileconsecutivedelimiter = false .textfiletabdelimiter = false .textfilesemicolondelimiter = false .textfilecommadelimiter = true .textfilespacedelimiter = false .textfilecolumndatatypes = array(1, 1, 1, 1, 1) .textfiletrailingminusnumbers = true .refresh backgroundquery:=false end range("d3:h4").select activesheet.shapes.addchart.select activechart.charttype = xlxyscatter activechart.setsourcedata source:=range("sheet1!$d$3:$h$4") end sub
essentially, because data inputted data.txt can length, program not work; goes d3:h3. i'd chart use data d3 hx, x end of data row. how this? helping idiot!
probably following work:
sub getdata() ... .... end lastrowcolh = range("h65536").end(xlup).row activesheet.shapes.addchart.select activechart.charttype = xlxyscatter activechart.setsourcedata source:=range("sheet1!$d$3:$h$" & cstr(lastrowcolh)) end sub
hth!
Comments
Post a Comment