title: excel formula match cells background color
body: <p>I'm after some help with this code I found on this site that I'm using but it doesn't quite do what I need.</p>
  
  <p><a href="https://stackoverflow.com/questions/25583313/excel-vba-match-font-color-and-cell-background-color">Code found here</a></p>
  
  <p>I have 2 sheets "Production" and "Components". "Production" is a list of data which includes a column(B) of job numbers. "Components" is a sheet of columns based on varies locations, in the cells below are job numbers.</p>
  
  <p>I need code that matches the cell background color of the numbers on "Components" to the cell background color of the same value on "Production" sheet.</p>
  
  <p>The code below does this but with 2 problems. </p>
  
  <p>First, it searches the entire column(B) in "Production" which can often have the same number repeated. I only need it to search until it finds the first instance it finds from the top of the sheet. </p>
  
  <p>Second, when the macro runs it takes ages to check through all the numbers, I need something quicker if possible?</p>
  
  <pre><code>Sub Worksheet_Update()
    Dim wsHighlight As Worksheet
    Dim wsData As Worksheet
    Dim rngColor As Range
    Dim rngFound As Range
    Dim KeywordCell As Range
    Dim strFirst As String
  
    Set wsHighlight = Sheets("Production")
    Set wsData = Sheets("Components")
  
    With wsData.Columns("A:M")
      For Each KeywordCell In wsHighlight.Range("B3", wsHighlight.Cells(Rows.Count, "B").End(xlUp)).Cells
        Set rngFound = .Find(KeywordCell.Text, .Cells(.Cells.Count), xlValues, xlWhole)
        If Not rngFound Is Nothing Then
          strFirst = rngFound.Address
          Set rngColor = rngFound
          Do
            Set rngColor = Union(rngColor, rngFound)
            Set rngFound = .Find(KeywordCell.Text, rngFound, xlValues, xlWhole)
          Loop While rngFound.Address &lt;&gt; strFirst
          rngColor.Interior.Color = KeywordCell.Interior.Color
        End If
      Next KeywordCell
    End With
  End Sub
  </code></pre>