I have a user form that accepts user input and is supposed to put it on a worksheet. The form control has 2 textboxes, and IngredientName and Percentage. The user enters info into these boxes and clicks "Add Ingredient". This is supposed to place IngredientName in Cell G10, and Percentage in Cell H10. It isn't doing this.
Furthermore, the user must be able to add ingredients until Cells G:H16 are full, then unload the form. It is unloading the Form every time the AddIngredient is clicked.
Please help, here is the code.
Furthermore, the user must be able to add ingredients until Cells G:H16 are full, then unload the form. It is unloading the Form every time the AddIngredient is clicked.
Please help, here is the code.
Code:
Private Sub AddIngredient_Click()
Dim r As Long 'used for sending data to worksheet
' Validate both text boxes before sending data
If IngredientName.Text = "" Then
MsgBox ("Please enter a name for the ingredient")
IngredientName.SetFocus
Exit Sub
End If
If Not IsNumeric(Percentage.Text) Then
MsgBox ("This box only accepts numeric values")
Percentage.SetFocus
Exit Sub
End If
' r will be the first blank after cell G9
r = WorksheetFunction.Max(10, Cells(Rows.Count, 7).End(xlUp).Offset(1).Row)
If r > 17 Then
Unload Me
Exit Sub
End If
Cells(r, 7) = IngredientName.Text 'send to first blank in column G
Cells(r, 8) = Percentage.Text
IngredientName.Text = ""
Percentage.Text = ""
IngredientName.SetFocus
End Sub