title: How to set background color of several cells at once
body: <p>I am trying to set a value and bgcolor for selected cells.
  Setting value works, unfortunately setting color does not work. Whats wrong in my code ?</p>
  <p><strong>my Code</strong></p>
  <pre><code>Function InRange(Range1 As Range, Range2 As Range) As Boolean
  
   Dim InterSectRange As Range
   Set InterSectRange = Application.Intersect(Range1, Range2)
   InRange = Not InterSectRange Is Nothing
   Set InterSectRange = Nothing
   End Function
  
  Sub test()
  
      If InRange(ActiveCell, Range(&quot;A1:AA40&quot;)) Then
      
          Set selectedRange = Application.Selection
          
             selectedRange.Value = &quot;That Works!&quot;
             selectedRange.Interior.ColorIndex = 1
         
      End If    
  End Sub
  </code></pre>