title: run-time error -2147417848 (80010108): method 'cells' of object_'Worksheet' failed
body: <p>I created a form to write data inside a table. I got an error every 3 times that I push the button to add data to the table. The error said: <strong>run-time error -2147417848 (80010108): method 'cells' of object_worksheet failed</strong>. Below you can find the code related to the button to add data to the form.
  When I debug the error the code row highlighted is always this one:
  <strong>.Cells(LastRow + 1, 1) = MaxId</strong></p>
  <p>I hope that someone could help me with that</p>
  <pre><code>Private Sub cmd_BillingAddNewBiilingItem_Click()
  
      Dim rng As Range
      Dim IdColumn As Range
      
      Set rng = ThisWorkbook.Worksheets(&quot;db_billing_items&quot;).ListObjects(&quot;tbl_billing_items&quot;).Range
      Set IdColumn = Worksheets(&quot;db_billing_items&quot;).ListObjects(&quot;tbl_billing_items&quot;).ListColumns(1).DataBodyRange
      
      Dim IdToLoad As Long
      Dim RowToLoad As Long
          
      Dim WshContract, WshOda As Worksheet
      Dim rngContract, rngOda As Range
      Dim ContractToLoad, OdaToLoad As String
      
      Set WshContract = ThisWorkbook.Worksheets(&quot;db_contracts&quot;)
      Set rngContract = WshContract.ListObjects(&quot;tbl_contracts&quot;).Range
      Set WshOda = ThisWorkbook.Worksheets(&quot;db_oda&quot;)
      Set rngOda = WshOda.ListObjects(&quot;tbl_oda&quot;).Range
          
      Dim LastRow As Long
      
      Dim MaxId As Double
      
      LastRow = rng.Find(What:=&quot;*&quot;, _
      After:=rng.Cells(1), _
      LookIn:=xlFormulas, _
      Lookat:=xlPart, _
      SearchOrder:=xlByRows, _
      SearchDirection:=xlPrevious, _
      MatchCase:=False).Row
      
      If IdColumn Is Nothing Then
          
          MaxId = 1
          
      Else
      
          MaxId = Application.WorksheetFunction.Max(IdColumn) + 1
          
      End If
            
      If (cbo_Billing_Client_Name = &quot;&quot; Or cbo_BillingCategory = &quot;&quot; Or txt_BillingAmount = &quot;&quot; Or txt_BillingInvoiceDate = &quot;&quot; Or txt_BillingObjectDescription = &quot;&quot; _
          Or txt_BillingItemDescription = &quot;&quot; Or txt_BillingItemName = &quot;&quot;) Then
          
          MsgBox Prompt:=&quot;One or more mandatory fields are missing&quot;, Buttons:=vbCritical, Title:=&quot;Incomplete purchase order data&quot;
      
      Else
                 
      With rng.Parent
                     
          .Cells(LastRow + 1, 1).NumberFormat = &quot;0&quot;
          .Cells(LastRow + 1, 1) = MaxId
          
          .Cells(LastRow + 1, 2).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 2).Value = txt_BillingItemName.Value
          
          .Cells(LastRow + 1, 3).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 3).Value = cbo_BillingCategory.Value
          
          .Cells(LastRow + 1, 4).NumberFormat = &quot;#,##0.00&quot;
          .Cells(LastRow + 1, 4).Value = txt_BillingAmount.Value
          
          If txt_BillingStartDate &lt;&gt; &quot;&quot; Then
              
              .Cells(LastRow + 1, 5).NumberFormat = &quot;dd/mm/yyyy&quot;
              .Cells(LastRow + 1, 5).Value = DateValue(txt_BillingStartDate.Value)
          
          End If
                  
          If txt_BillingEndDate &lt;&gt; &quot;&quot; Then
  
              .Cells(LastRow + 1, 6).NumberFormat = &quot;dd/mm/yyyy&quot;
              .Cells(LastRow + 1, 6).Value = DateValue(txt_BillingEndDate.Value)
          
          End If
          
          .Cells(LastRow + 1, 7).NumberFormat = &quot;dd/mm/yyyy&quot;
          .Cells(LastRow + 1, 7).Value = DateValue(txt_BillingInvoiceDate.Value)
  
          .Cells(LastRow + 1, 8).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 8).Value = txt_BillingObjectDescription.Value
  
          .Cells(LastRow + 1, 9).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 9).Value = txt_BillingItemDescription
  
          .Cells(LastRow + 1, 10).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 10).Value = cbo_Billing_Payment_terms.Value
  
          .Cells(LastRow + 1, 12).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 12).Value = txt_BillingInvoiceNumber.Value
  
          .Cells(LastRow + 1, 14).NumberFormat = &quot;@&quot;
          .Cells(LastRow + 1, 14).Value = cbo_Billing_Client_Name.Value
          
          If cbo_Billing_Contract_Name &lt;&gt; &quot;&quot; Then
              
              ContractToLoad = cbo_Billing_Contract_Name.Value
              
              RowToLoad = rngContract.Find(What:=ContractToLoad, _
              Lookat:=xlWhole, _
              LookIn:=xlFormulas, _
              SearchOrder:=xlByRows, _
              SearchDirection:=xlPrevious, _
              MatchCase:=False).Row
  
              .Cells(LastRow + 1, 15).NumberFormat = &quot;0&quot;
              .Cells(LastRow + 1, 15).Value = Application.WorksheetFunction.Index(rngContract, RowToLoad, _
                  Application.WorksheetFunction.Match(&quot;id_contract&quot;, WshContract.ListObjects(&quot;tbl_contracts&quot;).HeaderRowRange, 0))
          
          End If
          
          If cbo_Billing_Oda_name &lt;&gt; &quot;&quot; Then
              
              OdaToLoad = cbo_Billing_Oda_name.Value
              
              RowToLoad = rngOda.Find(What:=OdaToLoad, _
              Lookat:=xlWhole, _
              LookIn:=xlFormulas, _
              SearchOrder:=xlByRows, _
              SearchDirection:=xlPrevious, _
              MatchCase:=False).Row
  
              .Cells(LastRow + 1, 20).NumberFormat = &quot;0&quot;
              .Cells(LastRow + 1, 20).Value = Application.WorksheetFunction.Index(rngOda, RowToLoad, _
                  Application.WorksheetFunction.Match(&quot;id_oda&quot;, WshOda.ListObjects(&quot;tbl_oda&quot;).HeaderRowRange, 0))
          
          End If
          
          End With
          
          ThisWorkbook.Save
          
          Unload Me
          
      End If
      
  End Sub
  </code></pre>