我正在尝试读取 Sheet1 上的表值(从 A 列中的 URL 导入),然后将表值粘贴到 Sheet2 上,每个表值都在 Sheet2 上先前粘贴的 B 列中的表值正下方的行中。这些粘贴的行值通常每次都会更改(始终跨 10 列和可变的行数)。
下面的代码会将每个值 10 列粘贴到 Sheet2 的右侧,而不是粘贴到 B 列(Sheet2)和正确的行中。
任何建议都非常感谢。
以下是一些示例 URL http://hosteddb.fightmetric.com/fighters/details/994 http://hosteddb.fightmetric.com/fighters/details/993
Sub Macro2()
' Macro2 Macro
Dim WSO As Worksheet
Set WSO = ActiveSheet
Dim WS2 As Worksheet: Set WS2 = Worksheets("Sheet2")
NextRow = WS2.Range("A" & Rows.Count).End(xlUp).Row
'ctr = 1
ActiveWorkbook.Worksheets.Add
For Each cell In WSO.Range("A1:A7") 'There are over 2000 values in Column A
ThisURL = "URL;" & cell.Value
Application.CutCopyMode = False
Range("A1").Select
Selection.Copy
Application.CutCopyMode = False
Range("A1").Select
Set WS2 = ActiveSheet
With ActiveSheet.QueryTables.Add(Connection:= _
ThisURL, Destination:=WS2.Range("A" & NextRow))
' Range("A$" & NextRow)) Different variations i've tested
' Cells(ctr + 5, 1)) Different variations i've tested
.Name = "998"
.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 = "9"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
'ctr = ctr + 1
End With
Next cell
End Sub