Results 1 to 4 of 4
  1. #1
    bmcla is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Posts
    2

    Red face Creating unique ID but not for duplicate text rows


    Hi,
    I have an excel spreadsheet with about 20 fields. 2 of them include first_name and surname and I want to create a unique ID for each separate entry, however I don't want the same names getting different unique ID's. Can anyone help please??

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    First, sort the rows by the lastname, firstname columns. Then use VBA (macro) code to assign the ID value. Like:
    Code:
    Sub NewID()
    Dim strName As String
    Dim intID As Integer
    Dim i As Integer
    i = 1
    intID = 1
    With Worksheets("Sheet1")
        strName = .Cells(i, 2).Value & .Cells(i, 3).Value
        While .Cells(i, 2).Value & "" <> ""
            If strName <> .Cells(i, 2).Value & .Cells(i, 3).Value Then
                intID = intID + 1
                strName = .Cells(i, 2).Value & .Cells(i, 3).Value
            End If
            .Cells(i, 1).Value = "A" & intID
            i = i + 1
        Wend
    End With
    End Sub

  3. #3
    bmcla is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Posts
    2
    Thanks you so much. You have saved me a lot of work

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    If this solution is good for you then go ahead and use the Thread Tools and mark this thread as Solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Duplicate Query Reporting Unique Values...
    By Tomfernandez1 in forum Queries
    Replies: 5
    Last Post: 04-19-2011, 04:22 PM
  2. creating unique ID on existing table
    By TheShabz in forum Access
    Replies: 6
    Last Post: 01-24-2011, 03:53 PM
  3. Selecting Unique SETS of rows in Access Query
    By dalessandroh in forum Queries
    Replies: 0
    Last Post: 11-09-2010, 10:42 PM
  4. Creating a unique ID for a new set of values
    By slaterino in forum Programming
    Replies: 1
    Last Post: 08-24-2010, 09:35 AM
  5. Replies: 1
    Last Post: 08-18-2010, 02:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums