2015-02-03 1 views
0

평판이 10 개가 아니므로 이미지를 업로드 할 수 없으므로 설명이 훨씬 쉬워집니다. Mr. Excel forum here : http://www.mrexcel.com/forum/excel-questions/833202-visual-basic-applications-find-non-match-criteria-ws2-copy-criteria-ws1.htmlVBA 일치하지 않는 경우 하나의 워크 시트에서 ID 복사

두 개의 워크 시트가 있습니다. Employee ID가 "Sheet1"의 Employee ID와 일치하는 "Sheet2"에서 ​​Employee ID를 찾아야합니다. "Sheet2"에 "Sheet1"에없는 ID가 있으면 "Sheet2"의 해당 행에서 특정 셀을 "Sheet1"에 복사해야합니다.

그 위에 복사 할 때 이전 $ 금액이 올바른 위치에 오도록 복사 된 셀에 전체 행을 삽입해야합니다 (Mr. Excel의 게시물 참조). 아마 이치에 맞지 않습니다. 단지 나는 이미지를 업로드 할 수 있다면 ...

Option Explicit 

Sub CopyNonMatches() 

Dim ws1 As Worksheet, ws2 As Worksheet 
Dim ws1Range As Range, ws2range As Range 
Dim ws1Long As Long, ws2long As Long 

Set ws1 = ThisWorkbook.Sheets("Sheet1") 
Set ws2 = ThisWorkbook.Sheets("Sheet2") 

With ws1 
ws1Long = .Range("C" & .Rows.Count).End(xlUp).Row 
End With 

Set ws1Range = ws1.Range("C3", "C" & ws1Long) 

With ws2 
ws2long = .Range("C" & .Rows.Count).End(xlUp).Row 
End With 

Set ws2range = ws2.Range("C3", "C" & ws2long) 

'Now I need to compare the ranges 'ws1Range' with 'ws2Range' and if 'ws2Range' has ID's that... 
'...are not included in 'ws1Range', then I need to copy over info from Columns A to C from the row that had no match over to 'Sheet1'. 

??????????????????? 

End Sub 

답변

0

하위 CopyNonMatches()

Dim ws1 As Worksheet, ws2 As Worksheet 
Dim vIDs1 As Variant, vData As Variant 
Dim i As Long 

Set ws1 = ThisWorkbook.Sheets("Sheet1") 
Set ws2 = ThisWorkbook.Sheets("Sheet2") 

vIDs1 = ws1.Range("C2", ws1.Range("C" & Rows.Count).End(xlUp)).Value 
vData = ws2.Range("A2", ws2.Range("C" & Rows.Count).End(xlUp)).Value 

For i = 1 To UBound(vData, 1) 
    If IsError(Application.Match(vData(i, 3), vIDs1, 0)) Then 
     ws1.Rows(8).Insert 
     ws1.Range("A8:C8").Value = Array(vData(i, 1), vData(i, 2), vData(i, 3)) 
    End If 
Next i 

최종 하위

관련 문제