Question: VBA question I am trying to prevent duplicate entries on a spreadsheet through a userform. This is the code I came up with, but no
VBA question
I am trying to prevent duplicate entries on a spreadsheet through a userform.
This is the code I came up with, but no lock on running it on the code I have below to add items to the userform
' work on this right now this should keep you from duplicating values on your vba sheet lRow = lRow + 1 If Application.WorksheetFunction.CountIf(Range("A2:A" & lRow), Cells(lRow, 1)) > 1 Then MsgBox "Duplicate data!", vbCritical, "Remove data" Cells(lastrow, 1) = "" ElseIf Application.WorksheetFunction.CountIf(Range("A2:A" & lRow), Cells(lRow, 1)) = 1 Then answer = MsgBox("Are you sure you want to add data?", vbYesNo + vbQuestion, "Add Record") If answer = vbYes Then End If
---------------------------
Private Sub cmdadd_Click()
'Copy input values to sheet. Dim lRow As Long Dim ws As Worksheet Set ws = Worksheets("Quote Log") lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row With ws .Cells(lRow, 1).Value = Me.txtsqanum.Value .Cells(lRow, 2).Value = Me.txttype.Value .Cells(lRow, 3).Value = Me.txtdeptnum.Value .Cells(lRow, 4).Value = Me.txtissue.Value .Cells(lRow, 5).Value = Me.txtcust.Value .Cells(lRow, 6).Value = Me.txtval.Value .Cells(lRow, 7).Value = Me.txtponum.Value .Cells(lRow, 8).Value = Me.txttypejob.Value .Cells(lRow, 9).Value = Me.txtnote.Value .Cells(lRow, 10).Value = Environ("Username") ' who enters it End With 'Clear input controls. Me.txtsqanum.Value = "" ' Me.txttype.Value = "" Me.txtdeptnum.Value = "" Me.txtissue.Value = "" Me.txtcust.Value = "" Me.txtval.Value = "" Me.txtponum.Value = "" Me.txttypejob.Value = "" Me.txtnote.Value = ""
End Sub
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
