1
我正在嘗試查找給定列表的值,並將剩餘的行內容複製到列表的相鄰列中。我從這個網站複製了一些代碼,並在其他地方找到了找不到答案的東西。每次我運行代碼,它給了我一個編譯錯誤「無效的外部過程」Excel宏複製單元格區域並將數據粘貼到另一個表格
Sub test()
Dim LR As Long
Dim i As Long
Dim x As Long
Dim lastDataRow As Long
Dim lastListRow As Long
Dim sheetOne As String
Dim sheetTwo As String
Dim listItem As String
Dim dataItem As String
Dim listColNum As Long
Dim dataColNum As Long
listColNum = 1
dataColNum = 2
sheetOne = "new_copy"
sheetTwo = "Historical_data_"
lastListRow = Sheets(sheetOne).Cells(Sheets(sheetOne).Rows.Count, listColNum).End(xlUp).row
lastDataRow = Sheets(sheetTwo).Cells(Sheets(sheetTwo).Rows.Count, dataColNum).End(xlUp).row
For x = 1 To lastListRow
For i = 1 To lastDataRow
If Sheets(sheetOne).Cells(x, listColNum).Value = Sheets(sheetTwo).Cells(i, dataColNum).Value Then
Sheets(sheetOne).Cells(x, 3).Value = Sheets(sheetTwo).Cells(i, 3).Value
End If
Next i
Next x
End Sub
任何幫助,將不勝感激!
我刪除了原始模塊,插入一個新的,並在複製的代碼了。它運行得很好,然後。謝謝你的幫助。 – Celator