excel - VBA querytables loop placing retrieved data in not correct cells -
i'm creating little macro retrieve data website has table in rows of 30.
the problem when loop, every iteration of loop places data column @ right instead of below. mean, query retrieves data columns q until row 30. when next iteration want gets columns q row 31 61.
thing places columns r to... xx until row 30. guess issue might on destination:=range...
sub extract_data_table() ' ' extract_data_table macro ' = 1 41 x = 1 41 z = (x * 30) - 29 worksheets("nhl_results_rs").select worksheets("nhl_results_rs").activate mystr = "url;http://www.nhl.com/stats/game?fetchkey=20062allsatall&viewname=summary&sort=gamedate&gp=1&pg=" & x activesheet.querytables.add(connection:= _ **mystr, destination:=range("$a$1"))** '.commandtype = 0 .name = _ "game?fetchkey=20062allsatall&viewname=summary&sort=gamedate&gp=1&pg=1_2" .fieldnames = true .rownumbers = false .filladjacentformulas = false .preserveformatting = true .refreshonfileopen = false .backgroundquery = true .refreshstyle = xlinsertdeletecells .savepassword = false .savedata = true .adjustcolumnwidth = true .refreshperiod = 0 .webselectiontype = xlspecifiedtables .webformatting = xlwebformattingnone .webtables = "3" .webpreformattedtexttocolumns = true .webconsecutivedelimitersasone = true .websingleblocktextimport = false .webdisabledaterecognition = false .webdisableredirections = false .refresh backgroundquery:=false end next x end sub
could of help?
you correct in assuming problem lies in destination
. have never used command, after brief experimenting i've deducted if destination
occupied, paste data in nearest suitable space right of original destination.
to bypass this, should add offset
destination range, based on iterator, x
in example.
what did this:
destination:=range("$a$1").offset((x - 1) * 31, 0))
this work, you'll notice repeating column headers, guess you'll need experiment .fieldnames
bit well.
Comments
Post a Comment