title: How to change value of a cell based on cell fill color
body: <p>I have a spreadsheet in excel where there are three types of cell. Black cells, yellow cells and cells with no fill. I am trying to write code so that the black cells will contain value <code>1</code>, the yellow cells value <code>2</code> and the no fill cells value <code>0</code>.</p>
  <p>So far, this is what I have for the black and yellow cells:</p>
  <pre><code>Sub changeValuesBasedOnColour()
  
      Dim rg As Range
      Dim xRg As Range
      Set xRg = Selection.Cells
      Application.DisplayAlerts = False
      For Each rg In xRg
          With rg
              Select Case .Interior.Color
                  Case Is = 0   'Black
                      .Value = 1
                  Case Is = 255255 'Yellow
                      .Value = 2
              End Select
          End With
      Next
      Application.DisplayAlerts = False
  
  
  End Sub
  </code></pre>
  <p>This has worked for the cells in my spreadsheet which are filled black: they all now contain the value <code>1</code>. However, nothing has changed for my cells filled yellow.</p>
  <p>I thought that it could be to do with the wrong HEX code, but I have tried <code>2552550</code> and ```255255000`` as well. The yellow cells are filled with the yellow from the excel standard colors, as seen below.</p>
  <p><a href="https://i.stack.imgur.com/Wk1Kj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wk1Kj.png" alt="excel standard colours" /></a></p>