title: Add new row to excel Table (VBA)
body: <p>I have an excel which serves to record the food you ingest for a specific day and meal. I hav a grid in which each line represent a food you ate, how much sugar it has, etc. </p>
  
  <p>Then i've added an save button to save all the data to a table in another sheet.</p>
  
  <p>This is what i have tried</p>
  
  <pre><code>    Public Sub addDataToTable(ByVal strTableName As String, ByRef arrData As Variant)
      Dim lLastRow As Long
      Dim iHeader As Integer
      Dim iCount As Integer
  
      With Worksheets(4).ListObjects(strTableName)
          'find the last row of the list
          lLastRow = Worksheets(4).ListObjects(strTableName).ListRows.Count
  
          'shift from an extra row if list has header
          If .Sort.Header = xlYes Then
              iHeader = 1
          Else
              iHeader = 0
          End If
      End With
  
      'Cycle the array to add each value
      For iCount = LBound(arrData) To UBound(arrData)
          **Worksheets(4).Cells(lLastRow + 1, iCount).Value = arrData(iCount)**
      Next iCount
  End Sub
  </code></pre>
  
  <p>but i keep getting the same error on the highlighted line: </p>
  
  <pre><code>Application-defined or object-defined error
  </code></pre>
  
  <p>What i am doing wrong?</p>
  
  <p>Thanks in advance!</p>