Block Duplicate Data Saving

SkyGod

New Member
Joined
May 18, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have userform with 18 textboxes and I save datas with commandbutton as horizonal from A to T.

If same Data has in B column then it wont allow save the data. It's like a pre-save check before saved. I want link it to commandbutton.

B is Textbox1 on the UserForm.

Thanks for your time!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Adjust the name of your sheet in the code:

VBA Code:
Private Sub CommandButton1_Click()
  Dim f As Range
  
  With TextBox1
    If .Value = "" Then
      MsgBox "Enter textbox1"
      .SetFocus
      Exit Sub
    End If
    
    Set f = Sheets("Sheet1").Range("B:B").Find(.Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      MsgBox "Value already exists"
      Exit Sub
    End If
  End With
  '
  'continue your code
End Sub
 
Upvote 0
it works well but it made broken order of Listbox datas. How about this way, let the command button save the datas to the last row. After saved the datas if there is a duplicate data in B column then delete the row from A to T. I guess that way would be better for listbox. or clear cell values from A to T.
 
Upvote 0
it works well but it made broken order of Listbox datas.
I do not understand what you mean.


let the command button save the datas to the last row. After saved the datas if there is a duplicate data in B column then delete the row from A to T
If it already exists, then why add it and then delete it, just don't add it.
 
Upvote 0
I meant after saved the datas I check some part of the datas in the listbox. it's for updating the datas or deleting. Well no problem I learnt the way with your help. I guess I can do the rest.
Thank you for helping!
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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