title: Change interior color of range of cells without using loops
body: <p>How to make this work?</p>
  
  <pre><code>Range(Cells(1,1),Cells(height,width)).Interior.Color=colorArray
  </code></pre>
  
  <p>colorArray is one-dimensional array of Long Integers of length (width*height) containing color values.</p>
  
  <p>The above code returns</p>
  
  <blockquote>
    <p>Type mismatch error.</p>
  </blockquote>
  
  <pre><code>For i = 1 to height
     For j = 1 to width
        t=(i-1)*width+j
        Cells(i,j).Interior.Color=colorArray(t)
     Next
  Next
  </code></pre>
  
  <p>This code works but is too slow. I dont want to use loops.</p>
  
  <pre><code>Range(Cells(1,1),Cells(height,width)).Value=colorArray
  </code></pre>
  
  <p>This code fills the range with color values from the colorArray with no error. I want a similar code to change background color of cells of this range.</p>
  
  <p>Please help.</p>
  
  <pre><code>ReDim colorArray(1 To width*height) As Long
  </code></pre>
  
  <p>Sample code by Siddharth Rout:</p>
  
  <pre><code>Sub Sample()
      Dim colorArray(21) 'or Dim colorArray(21) As Long/Integer
      Dim Height As Long, Width As Long
  
      For i = 0 To 21
          colorArray(i) = i
      Next
  
      Height = 10
      Width = 2
  
      Range(Cells(1, 1), Cells(Height, Width)).Interior.Color = colorArray
  
  End Sub
  </code></pre>
  
  <p>This code also returns</p>
  
  <blockquote>
    <p>"Run-time error: '13' Type mismatch"</p>
  </blockquote>