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單元格比先前複製的單元格具有更多的列和行時,它將重新複製粘貼時未覆蓋的額外數據。我也可能做錯了事。 –