VBA网刮刀到一张纸上

我已经能够logging一个macros,并编辑它相当多。

它现在已经被设置为从网页(在链接上find)的特定数据,并显示在不同的页面上 – 我的问题是,现在我想要使用数据(VLOOKUP),但所有的数据是在不同的网页上,这使得它很难得到一个准确的公式。

如果有人可以请帮我编辑/指出我正确的方向进行更改 –

每个星期我都会把代码的第二行“”换成x = 1到20“换成”换x = 21再换成…“(例如) – 这样做是因为新的链接/数据每周都会出来

所以我不知道如何找出最后一行,并在下面添加下一批数据

Sub Update() For x = 1 To 20 Worksheets("Links").Select Worksheets("Links").Activate mystr = Cells(x, 8) mystr2 = Cells(x, 15) Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = x With ActiveSheet.QueryTables.Add(Connection:=mystr, Destination:=Range("$K$1")) .Name = "report2_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlAllTables .WebFormatting = xlWebFormattingNone .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With Range("A1").Select With ActiveSheet.QueryTables.Add(Connection:=mystr2, Destination:=Range("$A$1")) .Name = "report6_1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlAllTables .WebFormatting = xlWebFormattingNone .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With Next x End Sub 

提前致谢

代替

 for x = 1 to 20 

 for x = Range("A" & Rows.Count).End(xlUp).Row to Range("A" & Rows.Count).End(xlUp).Row-20 step -1 

它将find列A中使用的最后一个单元格,并从中减去20行并重复回溯