title: Excel VBA - compare three columns
body: <p>I'm new to VBA and would like some help creating a macro in Excel.</p>
  
  <p>I have a file with two sheets i wish to compare. I need to Compare Sheet 1 Column G (serial number) with Sheet 2 Column C (serial number) and if Sheet 2 Column K = D (Disposed Status) then highlight Sheet 1 Column G a colour.</p>
  
  <p>I have found this code on another thread however cannot get the "and" part to work.</p>
  
  <pre><code>**Sub Compare2()
  Dim ws1 As Worksheet
  Dim ws2 As Worksheet
  Set ws1 = Worksheets("Sheet1")
  Set ws2 = Worksheets("Sheet 2")
  For Each i In ws2.Range("G2:G30")
      For Each C In ws1.Range("C2:C50")
      For Each L In ws2.Range("K2:K50")
          If i.Cells.Value = C.Cells.Value And L.Cells.Value = "D" Then
                                 i.Cells.Interior.ColorIndex = 3
          End If
  
      Next
     Next
  Next
  End Sub**
  </code></pre>