VBA查询表循环将检索到的数据放在不正确的单元格中

我正在创build一个小macros来从具有30行的表的网站检索数据。

问题是,当我循环时,循环的每一次迭代都将数据放在右侧而不是下面的列中。 我的意思是,我的查询检索从列A到Q的数据,直到第30行。当我得到下一个迭代,我希望它得到列A到Q,但从行31到61。

事情是从列R到XX的地方,直到第30行。我想这个问题可能是目的地:=范围…

Sub Extract_data_table() ' ' Extract_data_table Macro ' For i = 1 to 41 For x = 1 To 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 With 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 With Next x End Sub 

你们能帮忙吗?

假设问题在于Destination你是正确的。 我从来没有使用这个命令,但经过一些简短的尝试,我已经扣除,如果Destination被占用,它会将数据粘贴到您最初的目的地右侧最适合的空间。

要绕过这个,你应该根据你的迭代器在你的例子中添加一个Offset到你的目标范围。

我做的是这样的:

 Destination:=Range("$A$1").Offset((x - 1) * 31, 0)) 

这是可行的,但是你会注意到你将重复列标题,所以我想你还需要尝试一下.FieldNames