title: How do I colour code cells based on inputs? Found a code but do not understand the "how"
body: <p>I need to colour code cells based on what is in that cell.</p>
  
  <ul>
  <li>Hard-coded numbers: blue</li>
  <li>Another worksheet reference: green</li>
  <li>Formulas: black</li>
  </ul>
  
  <pre><code>Sub mcrFinancial_Color_Codes()
      Dim rng As Range
      Dim rErr As Range
  
      On Error Resume Next
      For Each rng In Intersect(ActiveSheet.UsedRange, Selection)
          If rng.HasFormula Then
              Set rErr = Range(Mid(rng.Formula, 2, Len(rng.Formula) - 1)) 'Somehow sees if formula references another sheet???
              If CBool(Err) Then
                  rng.Font.ColorIndex = 1 'black
              Else
                  rng.Font.ColorIndex = 10 'green
              End If
              Err = 0
          ElseIf CBool(rng.Value) Then
              rng.Font.ColorIndex = 5 'blue
          Else
              rng.Font.ColorIndex = xlAutomatic 'default
          End If
      Next rng
      Set rErr = Nothing
  End Sub
  </code></pre>
  
  <p>I found this code but I don't understand some things after <code>If rng.HasFormula</code></p>
  
  <p>1) What does the <code>Set rErr</code> do and how does it differentiate formulas with cell references that contain an exclamation mark (!).</p>
  
  <p>2) <code>rErr</code> is a variable but is not actually referenced except in <code>Err</code>. Does the r represent something?</p>
  
  <p>3) <code>If CBool(Err)</code>. This somehow returns true for Err and labels it black, green otherwise. How does it get the boolean from Err?</p>