Results 1 to 3 of 3

Search duplicate before insert data using userform

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-06-2014
    Location
    malaysia
    MS-Off Ver
    Excel 2003/2010/2013
    Posts
    107

    Search duplicate before insert data using userform

    hi, Im creating a excel booklist for our library and im using userform to insert new entry of books details. could someone help me to fix my code to search duplicate for ISBN, title and call number. If this 3 entry no duplicate found, then only create/insert new booklist entry. So far im only managed to get this work for ISBN only.

    Option Explicit
    
    Private Sub CancelButton_Click()
    
    Unload Me
    
    End Sub
    
    
    Private Sub ClearButton_Click()
    
    Call UserForm_Initialize
    
    End Sub
    
    Private Sub OKButton_Click()
    
    Dim FoundCell As Range
    Dim Search As String
    Dim emptyRow As Long
    Dim i As Long
    Dim tmpStr As String
    Dim ws As Worksheet
    
    ''remove text for ISBN column
    tmpStr = ISBNTextBox.Value
        
        For i = 1 To Len(tmpStr)
            Select Case Mid$(tmpStr, i, 1) '//examine current char
                Case "0" To "9" '//permitted chars
                   '//ok
                Case Else
                   Mid$(tmpStr, i, 1) = "!"
            End Select
        Next i
        tmpStr = Replace$(tmpStr, "!", "") '//strip invalids & return
    
    ''check duplicate for ISBN column
    Set ws = Worksheets("booklist")
    emptyRow = ws.Cells(Rows.Count, 5).End(xlUp).Offset(1, 0).Row
    Search = ISBNTextBox.Text
    Set FoundCell = ws.Columns(5).Find(Search, LookIn:=xlValues, Lookat:=xlWhole)
    If FoundCell Is Nothing Then
    MsgBox "No existing ISBN found, inserted new list!"
    
    ''create new entry
    Cells(emptyRow, 1).Value = NoTextBox.Value
    Cells(emptyRow, 2).Value = TitleTextBox.Value
    Cells(emptyRow, 3).Value = AuthorTextBox.Value
    Cells(emptyRow, 4).Value = CopyTextBox.Value
    Cells(emptyRow, 5).Value = tmpStr
    Cells(emptyRow, 6).Value = CallNoTextBox.Value
    Cells(emptyRow, 7).Value = PublicationTextBox.Value
    
    Else
    MsgBox "ISBN exists!" & " data found at cell address " & FoundCell.Address
    End If
    
    If DeptCheckBox1.Value = True Then Cells(emptyRow, 8).Value = DeptCheckBox1.Caption
    
    If DeptCheckBox2.Value = True Then Cells(emptyRow, 8).Value = Cells(emptyRow, 8).Value & " " & DeptCheckBox2.Caption
    
    If DeptCheckBox3.Value = True Then Cells(emptyRow, 8).Value = Cells(emptyRow, 8).Value & " " & DeptCheckBox3.Caption
    
    
    End Sub
    
    Private Sub UserForm_Initialize()
    ''No. coulumn auto numbering
    Dim LstRw As Long
    LstRw = Cells(Rows.Count, "A").End(xlUp).Row
    Me.NoTextBox.Value = Cells(LstRw, "A").Value + 1
    NoTextBox.Value = Me.NoTextBox.Value
    ''Empty TextBox
    TitleTextBox.Value = ""
    AuthorTextBox.Value = ""
    CopyTextBox.Value = ""
    ISBNTextBox.Value = ""
    CallNoTextBox.Value = ""
    PublicationTextBox.Value = ""
    
    DeptCheckBox1.Value = False
    DeptCheckBox2.Value = False
    DeptCheckBox3.Value = False
    
    'Set Focus on NameTextBox
    NoTextBox.SetFocus
    
    End Sub
    https://www.excelforum.com/attachmen...1&d=1580278127
    Attached Files Attached Files
    Last edited by amein; 01-29-2020 at 02:25 AM. Reason: add details

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. USERFORM : Search and edit data in userform
    By mohit.kumar9094 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2018, 07:50 AM
  2. [SOLVED] How can I search a column for duplicate then transfer data from UserForm to next empy row?
    By gmr4evr1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-11-2016, 10:26 AM
  3. Userform, Search, copy an paste data from a userform database to another sheet.
    By masro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2015, 02:42 PM
  4. [SOLVED] Userform to search worksheet and display data back to the userform
    By zip247 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2015, 05:46 AM
  5. Replies: 0
    Last Post: 02-27-2014, 04:43 PM
  6. Duplicate a spreadsheet and insert data in it
    By khantouch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2013, 04:29 AM
  7. Search column a for duplicate data and copy entire row to duplicate sheet
    By crazyAMP in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2012, 08:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1