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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,445
Messages
6,172,177
Members
452,446
Latest member
walkman99

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