I have a procedure which finds the first empty row in order to add a new database entry via a user form.
An embedded button activates the userform.
I also have a procedure which detects whether you are editing an existing row - in which case it edits the existing row via user form - all you need to do is click in column A of the applicable cell and it puts your data back into the userform for editing.
The editing part works great - but when simply adding a new entry it is NOT succesfully identifying the first empty database row.
In fact, what happens is a new datasheet entry is added on whichever cell is highlighted.


Can anyone advise with ther below code and whether there is anything obviously wrong?

Many thanks,

Private Sub CB1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Referrals")
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myrng As Range
Dim myCell As Range


If AmmendFlag = True Then
iRow = Entry

Else
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
RowLoop:
If Cells(iRow, 1).Value = "" Then iRow = iRow1: GoTo RowLoop
'revised code to avoid problems with Excel tables in newer versions
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
End If