title: Array - Subscript out of range in VBA
body: <p>I am trying to store the values inside an array. I am facing a problem it says subscript out of range.</p>
  
  <p>This is the code,</p>
  
  <pre><code>Sub Trial()
  
  Dim HeaderArray() As Variant
  
  Dim HeaderValue As String
  
  Dim j As Long
  
  Dim i as Long
  
  set wk = Activeworkbook
  
  lastrow_header_Config = Wk.Sheets("Config").Cells(Rows.Count, "W").End(xlUp).Row
  
  j = 1
  
        For i = 2 To lastrow_header_Config
  
           HeaderValue = Wk.Sheets("Config").Range("W" &amp; i).Value
  
               If HeaderValue &lt;&gt; "" Then
  
                HeaderArray(j - 1) = HeaderValue // Subscript out of range error
  
               j = j + 1
  
               End If
  
        Next
  
  End Sub
  </code></pre>
  
  <p>What is the mistake I am making. Kindly advise.</p>