在表2具有在列A中的一組規則複製行
在實施例A列有每行中的多個代碼,根據對應於行B至H與數據該代碼。
在表1,我希望能夠以放置代碼之一,並且具有轉讓VBA行B:從表2 h如果此碼與一個在列A
這裏匹配時,該程序我有到目前爲止,它將行傳送過來,但不是正確的行。
Dim i As Integer
Dim x As Integer
Dim row As Integer
Dim oldRow As Integer
Dim found As Boolean
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
Dim rng As Range, cell As Range, rng2 As Range, cell2 As Range
Set rng2 = ws2.Range("A1:A212")
Set rng = ws1.Range("A1:A212")
row = 1
oldRow = 1
For Each cell In rng
row = row + 1
For Each cell2 In rng2
oldRow = oldRow + 1
If cell.Value = cell2.Value Then
row = row - 1
ws1.Cells(row, 2) = ws2.Cells(oldRow, 2)
ws1.Cells(row, 3) = ws2.Cells(oldRow, 3)
ws1.Cells(row, 4) = ws2.Cells(oldRow, 4)
ws1.Cells(row, 5) = ws2.Cells(oldRow, 5)
ws1.Cells(row, 6) = ws2.Cells(oldRow, 6)
ws1.Cells(row, 7) = ws2.Cells(oldRow, 7)
ws1.Cells(row, 8) = ws2.Cells(oldRow, 8)
found = True
End If
Next
found = False
oldRow = 1
Next
End Sub
謝謝幫助,謝謝。