2017-12-03 11 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ワークシートを1つの結合ワークシートとして扱います。@ 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 
関連する問題