(VBA Beginner) Row 15 is my first row of the table.
I can add data using a UserForm into Row 15 but i want to if i have data in Row 15 add into the next row (in my case Row 16 always +1) this is the function that im using:
Public Function GetLastRow(TargetWorksheet As Worksheet, ColumnNo As Variant) As Long
If TargetWorksheet Is Nothing Then Exit Function
GetLastRow = TargetWorksheet.Cells(TargetWorksheet.Rows.Count, ColumnNo).End(xlUp).Row
End Function
And this is my add button:
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("OIL_")
Dim GetLastRow As Long
'Validações-----------------------------------------------------
If Me.txtID.Value = "" Then
MsgBox "Insira um ID!", vbCritical
Exit Sub
End If
If Me.txtDesc.Value = "" Then
MsgBox "Insira uma Descrição!", vbCritical
Exit Sub
End If
'---------------------------------------------------------------
If GetLastRow + 1 <= 15 Then GetLastRow = 15 Else GetLastRow = GetLastRow + 1
sh.Cells(GetLastRow, 2).Value = Me.txtID.Value
sh.Cells(GetLastRow, 11).Value = Me.txtDesc.Value
sh.Cells(GetLastRow, 29).Value = Me.txtData.Value
End Sub
For now its only inserting data into my Row 15 and if i try to add another one it just replaces for the new data, i tried a lot of things and i cant manage to add data into the next row always.