I have to make a form that when I press a button I add a product to a table for a purchase ticket For that use the following code
Private Sub AMERICANO_Click()
Worksheets("Ticket_print").Activate
Dim L As Variant
Dim MyCount As Long
L = Hoja2.Range(Cells(Rows.Count, "A"), Cells(Rows.Count,
"c")).End(xlUp).Row + 1
MyCount = Application.CountIf(Range("B1:B50"), "Americano")
If MyCount = 0 Then
Cells(L, 2).Value = "Americano"
Cells(L, 1).Value = Cells(L, 1).Value + 1
Cells(L, 3).Value = 25
Else
Cells(L, 1).Value = Cells(L, 1).Value + 1
End If
End Sub
I have the same code on two different buttons What I would have to do is that when I pressed the button I would add the product to the table and if the product is already in the table then I should only increase the quantity without rewriting the product. When I press it once everything is fine (except that I do not put it in the row I wanted) but when I press it again it gives me the following
If someone could tell me what I did wrong or some way I would thank them