Macro to Check For Duplicates in multiple columns

ccsher77

New Member
Joined
Apr 7, 2011
Messages
12
Afternoon everybody,

I have contsructed a userform which consists of 2 Comboboxes boxes and 3 textboxes.
The comboboxes give the user an option to select Customer (combobox1) & Month (combobox 2)
The 3 Text boxes then allow the user to input various figures (not important)
Whnt the user clicks the command button the data on the userform is dumped into a spread sheet in 5 columns
the macro also check for the next empty row prior to dumping.
This portion of the macro works fine, however it dawned on me that with this set up the user would be able to enter duplicate data by selecting the same camobinations of customer and Month
(i.e Cust A Jan)

So I needed a method of preventing the Op from doing this, previousley I have used the code (below) to check for duplcate week no's in a given column,which worked well.

However I am struggling to modify it to look for 2 ducplicate conditions
(i.e To check that Customer A doesnt have more than one entry for January, February etc,)
Bearing in mind that in the first 2 columns there will be mulitple duplicates for customer and Month
i.e
Cust A Jan
Cust B Jan
Cust A Feb
Cust B Feb
etc etc...

Hope this is clear?

So my question is does any know how I can either modify the code below or have any different code that would aloow me to check for duplicates?


Code:
'Check For duplicate Week No Entry
With ws
If MsgBox("Are All Fields Correct?", 32 + vbYesNo, "QC Dept.") = vbNo Then Exit Sub
   If WorksheetFunction.CountIf(ws.Range("B2", ws.Cells(lRow, 1)), Me.ComboBox1.Value) > 0 Then
        MsgBox "Delivery Data For Week No:" & ComboBox1.Value & vbCrLf & "Already exists Please Try Again.", vbCritical, "QC dept."
        Exit Sub
    End If

Thank you in advance for any Help!!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,224,519
Messages
6,179,263
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top