I'm doing a Data Entry Table with a From using VBA. The code works fine, but it adds the entry to the first row after the table. For example, if the table's last row is row 20, then it will add the entry in row 21 outside of the table. Is there a way to assign the data to be added in the last row of the table?
This is the code I'm using to add the data to the table:
Private Sub buttonSave_Click()
If MsgBox("Deseas incluir este trabajo?", vbYesNo, "Guardar repuesto") = vbYes Then
'write the data to the worksheet from controls
Call WriteDataToSheet
'empty textboxes
Call EmptyTextBoxes
End If
End Sub
Private Sub WriteDataToSheet()
Dim newRow As Long
With Sheet1
newRow = .Cells(.Rows.Count, 2).End(xlUp).row + 1
.Cells(newRow, 1).Value = textboxNewDate.Value
.Cells(newRow, 2).Value = textboxNameNew.Value
.Cells(newRow, 3).Value = textboxNewEquipment.Value
.Cells(newRow, 4).Value = textboxNewTech.Value
.Cells(newRow, 5).Value = textboxNewCot.Value
.Cells(newRow, 6).Value = textboxNewPrice.Value
.Cells(newRow, 7).Value = textboxNewFac.Value
.Cells(newRow, 8).Value = textboxNewStatusF.Value
.Cells(newRow, 9).Value = textboxNewServ.Value
.Cells(newRow, 10).Value = textboxNewEnt.Value
.Cells(newRow, 11).Value = textboxNewDesc.Value
.Cells(newRow, 12).Value = textboxNewStatus.Value
End With
End Sub
This is the code I'm using to extract the range from the table. This is in a separate module.
Public Function GetType() As Variant
GetType = Sheet1.ListObjects("tbTabla2").DataBodyRange.Value
End Function
Is there a way I can assign the data to be added after the last row inside of "Tabla2".
