+ Reply to Thread
Results 1 to 3 of 3

Avoid Duplicate Names

Hybrid View

realniceguy5000 Avoid Duplicate Names 08-05-2010, 11:16 AM
EK1 Re: Avoid Duplicate Names 08-05-2010, 01:16 PM
Leith Ross Re: Avoid Duplicate Names 08-05-2010, 01:48 PM
  1. #1
    Registered User
    Join Date
    03-01-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Avoid Duplicate Names

    Maybe you could try posting a sample workbook so the concept is clearer. I'm confused as to where exactly you are entering the last and first names.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Avoid Duplicate Names

    Hello Mike,

    It is easier and faster to use the Dictionary Object. The Dictionary allows you to randomly check if something already exists. Here is an example...
    Sub Check_B()
    
      Dim Cell As Range
      Dim MyName As Variant
      Dim MyNames As Object
      Dim Rng As Range
      Dim RngEnd As Range
      
        Set Rng = Range("A3:B3")
        Set RngEnd = Cells(Rows.Count, Rng.Column).End(xlUp)
        If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Range(Rng, RngEnd)
        
        Set MyNames = CreateObject("Scripting.Dictionary")
        MyNames.CompareMode = vbTextCompare
        
          For Each Cell In Rng.Columns(1).Cells
            MyName = Cell.Text & " " & Cell.Offset(0, 1).Text
            If Not MyNames.Exists(MyName) Then
               MyNames.Add MyName, 0
            Else
              MsgBox "That Name Already Exists !!! Please Try Again...", vbCritical, "Name Exists"
              Cell.Resize(1, 2).ClearContents
              Call LastName
            End If
          Next Cell
         
        Set MyNames = Nothing
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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