2017-12-03 8 views
0

워크 시트 ("데이터베이스 확인")와 워크 시트 ("시민 DB")간에 특정 값을 검색, 일치 및 가져 오는 코드를 작성할 수있었습니다.VBA 검색 및 일치하는 값이 다른 여러 개의 시트

For rw = 2 To .Cells(.Rows.Count, "C").End(xlUp).row 
     mtch = Application.Match(.Cells(rw, "C").Value, wsc.Columns("A"), 0) 
워크 시트라는 두 번째 시트도 ("검색"을) 어떻게 워크 시트에 열을 검색 할 에 코드를 추가 할 수 있습니다 ("검색") 워크 시트에

If IsError(mtch) Then 
      .Cells(rw, "E") = .Cells(rw, "B").Value & " " & .Cells(rw, 
    "C").Value 
      wser.Cells(rw, "N") = .Cells(rw, "B").Value 
      wser.Cells(rw, "O") = .Cells(rw, "C").Value 

갈 것이다 발견되지

값 ("여객기")

Dim rw As Long, mtch As Variant, wsc As Worksheet 

    Set wsc = Worksheets("Civil DB") 
    Set wser = Worksheets("Search") 
    Set wsa = Worksheets("Airliners") 

    With Worksheets("Check Database") 
     For rw = 2 To .Cells(.Rows.Count, "C").End(xlUp).row 
      mtch = Application.Match(.Cells(rw, "C").Value, wsc.Columns("A"), 0) 


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


      If IsError(mtch) Then 
       .Cells(rw, "E") = .Cells(rw, "B").Value & " " & .Cells(rw, "C").Value 
       wser.Cells(rw, "N") = .Cells(rw, "B").Value 
       wser.Cells(rw, "O") = .Cells(rw, "C").Value 

      Else 
       .Cells(rw, "D") = wsc.Cells(mtch, "B").Value 


      End If 
     Next rw 
+0

지금 코드는 wsc 워크 시트의 Col A에서 일치하는 값을 찾습니다. wsa 워크 시트에서 Col A 값을 추가로 검색하고 싶습니다. 나머지 복사 조건은 동일하게 유지됩니다. – FotoDJ

+0

그래서 wsc 워크 시트와 wsa 워크 시트를 결합 된 단일 워크 시트로 취급합니다 ... @ YowE3K – FotoDJ

답변

1

당신은 단지 "남북 DB"시트의 일치가없는 경우 시트를 "여객기"확인 (및 사용) 할 가정, 난 당신이 생각 후 :

'... 
For rw = 2 To .Cells(.Rows.Count, "C").End(xlUp).row 
    mtch = Application.Match(.Cells(rw, "C").Value, wsc.Columns("A"), 0) 
    If IsError(mtch) Then 
     'No match found in Civil DB, try in Airliners 
     mtch = Application.Match(.Cells(rw, "C").Value, wsa.Columns("A"), 0) 
     If IsError(mtch) Then 
      'No match in Airliners either, so treat as error 
      .Cells(rw, "E") = .Cells(rw, "B").Value & " " & .Cells(rw, "C").Value 
      wser.Cells(rw, "N") = .Cells(rw, "B").Value 
      wser.Cells(rw, "O") = .Cells(rw, "C").Value 

     Else 
      'Match in Airliners, so store value 
      .Cells(rw, "D") = wsa.Cells(mtch, "B").Value 
     End If 
    Else 
     'Match in Civil DB, so store value 
     .Cells(rw, "D") = wsc.Cells(mtch, "B").Value 
    End If 
Next rw