title: VB Macros in two worksheets that compare 4 fields and then paste a value
body: <p>I am new to VB so any help you can provide would be great.  I have two worksheets.   They have four fields in common between the two sheets.  The rows will have many more fields that will not match.   if the four fields match then I need to paste two fields into the second sheet. </p>
  
  <p>Although this works it is hardcoded and I have to do this for each line. </p>
  
  <p>I would like to create a double loop and allow the four fields on the row to compare to the second sheet to each row to see if there is a match.  if so it will paste the two fields other wise it will go on to the next row in the first sheet and do the process again.</p>
  
  <pre><code>If [w2.Range.("b2")] = [w1.Range.("g3")] Then
    If [w2.Range.("c2")] = [w1.Range.("b3")] Then
     If [w2.Range.("d2")] = [w1.Range.("c3")] Then
       w1.Select
       Range("N3:O3").Select
       Selection.Copy
       w2.Select
       Range("G2:H2").Select
       ActiveSheet.Paste
   End If
   End If
   End If
  </code></pre>
  
  <p>Any help would be great.</p>
  
  <p>I got the two sheets worked and basically the comparison.   the only issue I have now is how the loops and incrementing  and not going down to the next row. </p>
  
  <pre><code>Sub Macro1()
  '
  ' Macro1 Macro
  '
  Set w1 = Worksheets("DDR_Mar'17")
  Set w2 = Worksheets("Release DrillDown")
  Dim drea As String
  Dim seva As String
  
  SelRow = Selection.Row
  
  'category ITSR on "DDR_Mar'17" sheet
     itsra = w1.Cells(SelRow, 7)
  'category Application on "DDR Mar'17" sheet
     appa = w1.Cells(SelRow, 2)
  'category SubCategory on "DDR Mar'17" sheet
     scata = w1.Cells(SelRow, 3)
  'category DRE on "DDR Mar'17" sheet
     drea = w1.Cells(SelRow, 14)
  'category SEV on "DDR Mar'17" sheet
     seva = w1.Cells(SelRow, 15)
  
  
  lr = w1.Cells(Rows.Count, 1).End(xlUp).Row
  
  SelRow = Selection.Row
  'category ITSR on "Release Drilldown" sheet
     itsrb = w2.Cells(SelRow, 2)
  'category Application on "Release Drilldown" sheet
     appb = w2.Cells(SelRow, 3)
  'category SubCategory on "Release Drilldown" sheet
     scatb = w2.Cells(SelRow, 4)
  'category DRE on "Release Drilldown" sheet
     dreb = w2.Cells(SelRow, 7)
  'category SEV on "Release Drilldown" sheet
   '  sevb = w2.Cells(SelRow, 8)
  
  lr2 = w2.Cells(Rows.Count, 1).End(xlUp).Row
  
  
  For x = 1 To lr2
     w2.Cells(x, 1) = x
   For y = 1 To lr
     w1.Cells(y, 1) = y
  
    If itsra = itsrb Then
      If appa = appb Then
       If scata = scatb Then
            w = w + 1
    End If
    End If
    End If
  
  Next y
  Next x
  
  End Sub
  </code></pre>