I think you are confusing NextRow and LastRow. Your button for "last" is supposed to take you to the last record in your sheet. The nextrow will be the blank row just below it where the new record will be entered. RoyUK gave you code for that next row:
Function NextRow(Optional sht As Worksheet) As Long
If sht Is Nothing Then Set sht = ActiveSheet
With sht
NextRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End With
End Function
Notice that the line: NextRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1, finds the last used row and adds 1 to it to move to the blank line below it to insert the new record.
Your form Initializer:
Private Sub UserForm_Initialize()
LastRow = FindLastRow
GetData
End Sub
is ok (notice that you are looking for the last used row/record in this case). Therefore you must modify the Roy's code to replace your your looping code:
Function FindLastRow(Optional sht As Worksheet) As Long
If sht Is Nothing Then Set sht = ActiveSheet
With sht
FindLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
End Function
Since this is the row number of the last record, you must remember to add 1 to that number when you want to insert a new record at the end of your database.
Bookmarks