Prevent duplicate value in userform

mynameisdarn

New Member
Joined
Mar 1, 2018
Messages
1
Hi,

Im super new here. I have been trying to figure based on the old post. But seems i cant get it right. I tried to copy few codes that i found online to prevent the duplicate values on a data form that i created.

Im trying to avoid duplication for range B2:B299

RowCount = Worksheets("Data2").Range("B1").CurrentRegion.Rows.Count
With Worksheets("Data2").Range("A1")
.Offset(RowCount, 1).Value = Me.txtMembership.Value

Thank you so much!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,

In this example I created a basic user form with one text box and one button, the button has the code below behind it

This code counts all your rows using column A, then will check the value in the textbox against column B, if it exists then it will display a message and give you the row number.

I use UCASE here as I used this on names for an entry form, and in case someone types Davidson or Davidson, this search will always match. This will work with numbers as they just don't change case :)

hope it helps you out

Code:
Private Sub CommandButton1_Click()

    Dim search_a As String
    Dim matchFound As Boolean
    Dim matchCount, matchRow, i As Long

search_a = TextBox1.Value
matchFound = False
matchCount = 0
matchRow = 0

    For i = 1 To Cells(Columns(1).Rows.Count, 1).End(xlUp).Row 'counts column A for last row
        If (UCase(search_a) = UCase(Cells(i, 2).Value)) Then 'checks to see if value in column b exists
        matchCount = matchCount + 1
        matchRow = i
        matchFound = True
    End If
Next


If matchFound = False Then
    ElseIf matchCount >= 1 Then
    MsgBox "This value exists!" & vbCr & vbCr & "Please check row " & matchRow
        Else
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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