I wish to pop up a message box "duplicate item" and not allow the item add when the user adds the same item in cart
Here is my code, but it only works start from 2nd row of the cart:
Sub addcart()
Dim lastrow As Long
Dim i As Integer, j As Integer, m As Integer
Dim x As Variant
lastrow = Sheets("Sales Point").Range("F" & Rows.Count).End(xlUp).Row
x = Cells(lastrow, 7).Offset(-1, 0).Value
If Range("C3").Value = "Please Select Option" Then
MsgBox "Please Select Option!"
Else
If Range("C6").Value = "Please Enter a Quantity" Then
MsgBox "Please Enter a Quantity!"
Else
If x = Cells(lastrow, 7) Then
MsgBox "Duplicate Entry!"
Else
For i = 5 To lastrow + 1
Cells(i, 5).Value = i - 4
Next
Cells(lastrow + 1, 6) = Range("C4")
Cells(lastrow + 1, 7) = Range("C3")
Cells(lastrow + 1, 8) = Range("C6")
Cells(lastrow + 1, 9) = Format(Range("C5"), "Currency")
Cells(lastrow + 1, 10) = Format(Cells(lastrow + 1, 9) * Cells(lastrow + 1, 8), "Currency")
For m = 1 To 4
For j = 0 To 5
Range("E" & Rows.Count).End(xlUp).Offset(0, j).Font.Bold = False
Range("E" & Rows.Count).End(xlUp).Offset(0, j).Borders().LineStyle = xlNone
Range("E" & Rows.Count).End(xlUp).Offset(m, j).Clear
Next j
Next m
End If
End If
End If
Worksheets("Sales Point").Columns("E:J").HorizontalAlignment = xlCenter
End Sub
This is how my worksheet looks like
