Hi,
I am trying to write a piece of code to prevent duplicate date entry. The document is designed to have new data entered at the end of each work day (Saturdays included). Sundays and public holidays not included. The way I would like it done is when the user runs the macro, a inputbox appears and asks the user to enter the date ("DD/MM/YYYY"). I can't for the life of me work out how to implement a duplicate entry detection system.
My idea to solve this is to search the entire column which contains the date (G) for the entered date.
I've been googling for a couple of hours now with no solution.
This is the closest I've gotten which still does not work.
Note: The date is stored as a value i.e. 2nd of Jan 2020 (2/1/2020) = 43832
I am quite new to this so any help is appreciated ! Thanks!
I am trying to write a piece of code to prevent duplicate date entry. The document is designed to have new data entered at the end of each work day (Saturdays included). Sundays and public holidays not included. The way I would like it done is when the user runs the macro, a inputbox appears and asks the user to enter the date ("DD/MM/YYYY"). I can't for the life of me work out how to implement a duplicate entry detection system.
My idea to solve this is to search the entire column which contains the date (G) for the entered date.
I've been googling for a couple of hours now with no solution.
This is the closest I've gotten which still does not work.
VBA Code:
newdate = Application.InputBox("Enter the date you would like to Add (DD/MM/YYYY)", "Day Diary Addition", FormatDateTime(Date, vbShortDate), Type:=1)
DateFINDER = Application.Match(newdate, Range("G:G"), 0)
If newdate = 0 Then 'prevents no input being entered
MsgBox "Entered Date not valid"
Exit Sub
End If
'checks to see if date has already been inserted
Set foundcell = ActiveSheet.Columns(7).Find(newdate, LookIn:=xlValues, lookat:=xlWhole)
If Not foundcell Is Nothing Then
MsgBox "Duplicate Entry Warning"
End Sub
End If
Note: The date is stored as a value i.e. 2nd of Jan 2020 (2/1/2020) = 43832
I am quite new to this so any help is appreciated ! Thanks!