The following code is for an OK command button that will insert a row after the last row of the selected weight:
Private Sub cmdOK_Click()
Dim FindRange As Range
Dim r As Long
If Not IsNumeric(txtWeight.Value) Then
MsgBox "Please enter a numberic value for weight"
Exit Sub
End If
Set FindRange = ActiveSheet.Columns(1).Find(What:=txtWeight.Value, After:=ActiveSheet.Cells(1, 1), LookAt:=xlWhole, SearchDirection:=xlPrevious)
If Not FindRange Is Nothing Then
r = FindRange.Rows.Row + 1
Else
r = 2
Do While ActiveSheet.Cells(r, 1).Value < CLng(txtWeight.Value) And ActiveSheet.Cells(r, 1).Value <> vbNullString
r = r + 1
Loop
End If
ActiveSheet.Rows(r).Insert
ActiveSheet.Cells(r, 1).Value = txtWeight.Value
Unload Me
End Sub
Bookmarks