title: Excel VBA sum with dynamic range
body: <p>I'm trying to create a excel macro calculating a sum of values in column A, using a certain dynamic range.</p>
  
  <p>Basic excel example screenshot included below:</p>
  
  <p><img src="https://i.stack.imgur.com/Biu3v.png" alt="Excel snapshot"></p>
  
  <p>The final goal is to loop through the cells in column B till a "0" is reached. When a "0" is reached, in column A of that same row, a sum of all the values in column A is calculated until a new "0" in column B is reached. 
  So in this basic example A1 should contain =sum(A2:A7) and A8 should contain the sum of the values A9 through A14.</p>
  
  <p>My progress so far included below, still pretty new at all the VBA stuff.</p>
  
  <pre><code>Sub sumtill0()
  '
  ' sumtill0 Macro
  '
  
  '
  Cells(ActiveCell.Row, 1).Select
  If Sheets("Blad1").Cells(2, 1).Value = nil And Sheets("Blad1").Cells(2, 1).Value &lt;&gt; "0" Then
      Sheets("Blad1").Activate
      Cells(2, 1).Range("A1").Select
         Else
      Dim artTekst As String
      If Sheets("Blad1").Cells(1, 2).Value = "0" Then
          Sheets("Blad1").Cells(1, 1).Fomula = "=SUM()"
      Else
          If Sheets("Blad1").Cells(1, 2).End(xlDown).Value = "0" Then
              Sheets("Blad1").Cells(1, 1).End(xlDown).Offset(1, 0).Value = "0"
              Sheets("Blad1").Cells(1, 1).End(xlDown).Fomula = "=SUM(???)"
              ActiveCell.Value = Sheets("Blad1").Cells(1, 2).End(xlDown).Offset(0, -2).Value
      End If
  
  End If
  
  End If
  
  End Sub
  </code></pre>
  
  <p>Thanks :)</p>