conditional userform data

luvbite38

Active Member
Joined
Jun 25, 2008
Messages
368
Hi,

I am tottaly new with the userform and hoping if someone can kindly help me figure the following out pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee... (meow face)

I am using a userform with text boxes and comboboxes for users to enter the data.

Than I am using following to feed the users entry into the worksheet called "Data"

PHP:
 .Offset(0, 1).Value = Country.Text

I am wondering if it is possible to tell the macro that do not enter the text.box value if it is a duplicate?

lets say if UK is already present in the Data worksheet in Column C:C, don't populate that entry and move on to the next on without showing any error or something?

Hope it makes sense?

Kind Regards
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello luvbite38,

The easiest way to check the range for duplicates is to use the CountIf function in VBA. Here is an example:
Code:
    If WorksheetFunction.CountIf(Range("C:C", Country.Text) > 1 Then
       MsgBox "The value " & Country.Text & " has already been entered."
       Exit Sub
    End If
 
Upvote 0
Thanks Ross,

I really appreciate it,

I still want to skip any message box or error messages.

All I want a If condition which would skip entering the information if the value is duplicate.

Kindly any suggestion would be much appreciated,
 
Upvote 0
Hello luvbite38,

Enclose you code within the If Then statement, like this...
Code:
    If WorksheetFunction.CountIf(Range("C:C", Country.Text) = 1 Then
       .Offset(0, 1).Value = Country.Text
    End If
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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