View Full Version : [SOLVED:] Check if data is already exist before adding a new data
cjvdg
01-21-2021, 06:17 PM
Hello! So, I'm currently having a problem in my data entry. Just want to ask if how can I avoid duplicates? So on my worksheet, I have an ADD sheet that the user is going to use to enter the data. Then I have the DATA sheet where all of the data is. The unique key is the STUDENT ID. Thank you in advance!
mancubus
01-22-2021, 02:19 AM
Sub add_stud()
If Application.CountIf(Worksheets("Data").Columns(3), Range("a_studID").Value) > 0 Then
MsgBox "Existing student ID in database! Quitting...", vbOKOnly, "Duplicate entry!"
Exit Sub
End If
With Worksheets("Data")
next_row = .Range("C" & .Rows.Count).End(xlUp).Offset(1).Row
.Cells(next_row, 3).Value = Range("a_studID").Value
.Cells(next_row, 4).Value = Range("a_lname").Value
.Cells(next_row, 5).Value = Range("a_fname").Value
.Cells(next_row, 6).Value = Range("a_ext").Value
.Cells(next_row, 7).Value = Range("a_mname").Value
End With
ThisWorkbook.Save
MsgBox "Data has been saved!", vbOKOnly + vbInformation, "SF10"
End Sub
cjvdg
01-24-2021, 06:03 PM
Sub add_stud()
If Application.CountIf(Worksheets("Data").Columns(3), Range("a_studID").Value) > 0 Then
MsgBox "Existing student ID in database! Quitting...", vbOKOnly, "Duplicate entry!"
Exit Sub
End If
With Worksheets("Data")
next_row = .Range("C" & .Rows.Count).End(xlUp).Offset(1).Row
.Cells(next_row, 3).Value = Range("a_studID").Value
.Cells(next_row, 4).Value = Range("a_lname").Value
.Cells(next_row, 5).Value = Range("a_fname").Value
.Cells(next_row, 6).Value = Range("a_ext").Value
.Cells(next_row, 7).Value = Range("a_mname").Value
End With
ThisWorkbook.Save
MsgBox "Data has been saved!", vbOKOnly + vbInformation, "SF10"
End Sub
It worked! Thank you so much!
mancubus
01-26-2021, 02:05 AM
you are welcome.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.