PDA

View Full Version : VBA Check for Duplicates in Multiple Columns from Userform



craigos
07-04-2012, 01:45 PM
Hi All,

I have some great code for a CommandButton on a UF that will input Data to a Worksheet and gives message box that duplicate is found.

Despite much searching I cannot find the answer to my problem.

What I have now:

A table that shows the Date, Start Time, End Time, Telekit Name and Chair.
The data is input to the sheet from a UF - all values are entered from TextBoxes.
When the data is input via a CmbBtn it checks for duplicate values (but only in the Date TextBox) and if found a message box shows and the user must then select another Date.

This works but it only checks against the Date.

What I need:

When data is input, 3 columns need to be checked.
The Date needs to be checked along with the Start Time and the End Time - 3 column duplicate Find.

Problems:

Having tried variations on this theme, if i was to input 04 Jul 12 09:00 09:30 then data is entered....however, if I enter 04 Jul 12 09:05 09:30 then the data is still entered which actually is a clash because the time is already allocated but the table accepts the data because the start time is 5 minutes later - trust that makes sense.

The Ideal World:

Input Date, Start and End times, (Telekit Name & Chair) select CmdBtn...macro checks for a duplicate Date, Start and End Time and if a duplicate is found a message box shows stating a duplicate is found ( ideally the message box gives the detail of the duplicate i.e. says 'Duplicate Found' and shows what it is - Date, Start & End Time only - by showing the duplicate in the message box, the user can then change the Start and End Time accurately.

I have attached a sample of what I have so far which is a pretty sad example but I am stumped!!!!!

Any help is as usual greatly appreciated.

Craig

sassora
07-04-2012, 02:15 PM
Perhaps use a for loop to see if any of the start / end times in the list match the ones that are being inputted?

craigos
07-10-2012, 12:15 PM
Thanks sassora, could you give me a steer how I can incorporate that into my code

sassora
07-11-2012, 01:39 PM
Have you thought about using Outlook for this?

The calendar is almost built for this type of thing