title: Adding Cell Value to an Integer (Excel-VBA)
body: <p>With years of programming experience (beginner with VBA, however), online references, and search engines I'm yet frustrated to the utmost with my inability to get this to work.</p>
  <p>I've spent at least two hours trying every combination of CInt, .Range, With/End With, .Value, Cells, etc. that I could possibly think of and it just keeps failing on the &quot;sum = sum + ...&quot; line:</p>
  <pre><code>Public Sub Fill_InnerData()
  
      Dim GNumber As Range
      Set GNumber = Range(&quot;GenerateNumber&quot;)
  
      Dim Data As Range
      Set Data = Range(&quot;DATA_INNER&quot;)
  
      For r = 1 To Data.Rows.Count
  
          For c = 1 To Data.Columns.Count
      
              If Data.Cells(r, c) = &quot;&quot; Then
              
                  If c &gt; r Then
              
                      Data.Cells(r, c) = 0
              
                  Else
                      Dim x As Integer
                      x = r - c + 1
                  
                      Dim y As Integer
                      y = 2
              
                      Dim sum As Integer
                      sum = 1
                  
                      For i = 1 To c
                          sum = sum + CInt(Worksheets(&quot;Data&quot;).Range(Cells(x, y)).Value)
                          y = y + 1
                      Next
                  
                  End If
              
              End If
  
          Next
      Next
  
  End Sub
  </code></pre>
  <p>By &quot;failing&quot; I mean getting this error:</p>
  <blockquote>
  <p>Run-time error '1004':</p>
  <p>Application-defined or object-defined error</p>
  </blockquote>
  <p>I've received that error at the mentioned line with EVERY combination that I tried.</p>
  <p>What am I doing wrong?</p>