0
我正在尝试读取表Sheet1上的值(从列A中的URL导入)&然后将表格值粘贴到Sheet2上,其中的每个值位于行正下方的行中以前在Sheet2的B列中粘贴的表值。这些粘贴的行值通常会每次更改(始终跨越&变量的行数为10列)。Excel VBA-将数据复制到同一工作表中
下面的代码将每个值10列粘贴到Sheet 2上的权利, 而不是进入塔B(Sheet 2中),&正确的行。
任何建议,非常感谢。
下面是一些示例网址的 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
是的,它完美的作品。非常感谢。我试了几天才得到它,但这需要花费数周的时间。再次感谢你 –
没问题。当你有机会时,你能将答案标记为正确吗? – rwisch45
1件事我注意到了。当复制的URL单元格比先前复制的单元格具有更多的列和行时,它将重新复制粘贴时未覆盖的额外数据。我也可能做错了事。 –