Popup alert if value already exists in column when entering data through a UserForm

thechad

Board Regular
Joined
Apr 28, 2014
Messages
118
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Greetings,

I am having trouble finding VBA code that suits my needs and am hoping someone can provide assistance.

I have a client profile worksheet that users populate through a UserForm. They enter first name and last name through 2 separate textboxes within the form along with some other required data. When they click on "Enter Profile", the data goes into a worksheet with the first and last being entered into separate columns on the same row (A & B). Column D uses formulas to join to names together in this format: last name, first name on each row. I would like the macro to go through Column D and if the client exists, generate a msgbox with a warning and then exit the sub.

Any assistance would be appreciated.

Thanks,
C
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
like this ?

VBA Code:
Private Sub CommandButton1_Click()
    With Sheet1
    ls = .Cells(Rows.Count, 1).End(xlUp).Row
    
        If Application.CountIf(.Range("A1:A" & ls), TextBox1.Text) > 0 And Application.CountIf(.Range("B1:B" & ls), TextBox1.Text) > 0 Then
            MsgBox "Duplicate Name"
            Unload Me
        Else
            .Range("B" & Rows.Count).End(xlUp).Offset(1).Value = TextBox1.Text
            .Range("A" & Rows.Count).End(xlUp).Offset(1).Value = TextBox2.Text
            .Range("B" & Rows.Count).End(xlUp).Offset(, 2).Value = Application.Concat(TextBox1.Value, " ", TextBox2.Value)
        End If
        
    End With
    
    Unload Me
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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