Prevent duplicate in userform if range cell is specific color.

flavioso

New Member
Joined
Oct 29, 2008
Messages
20
Hello.

Right now on a user form, I have an If statement that when a part is listed, it checks to see if it's a duplicate. What I would like to do is if the cell color in the range is Yellow (VB colorindex is 6) then it allows for a duplicate entry, but if the cell color is not yellow, then it prevents a duplicate. Right now I am using the following code to prevent all duplicated. Does anyone have any advice?


Code:
    If WorksheetFunction.CountIf(ws.Range("D4:D500", ws.Cells(iRow, 1)), Me.txtPN.Value) > 0 Then
        MsgBox "Duplicate Part Number! This part is already on list.", vbCritical
        Exit Sub
    End If

Thanks

Brad
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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