Assign Unique ID, After Data Sorts

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
Is there a way to assign a unique key to records, after they have been sorted? I have code that currently reads the value of a cell in the last row and adds 1 to it. The issue is, I have to sort the same sheet, which will inevitably cause the numbers to become non-sequential. I was thinking it may have something to do with a MAX function, but I'm not seeing anything on this forum or google, that guides me there. Thoughts? Here is what I have so far:

Code:
If ws1.Range("D2") = "" Then    Me.txt_Key = "1"
Else
    Me.txt_Key = ws1.Range("D" & LastRow - 1).Value + 1
End If
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Update on what I'm looking for, and where I'm at.

I've been able to assign a Unique ID based on the code below.
Code:
If ws1.Range("D2") = "" Then    Me.txt_Key = "1"
Else
    Me.txt_Key = ws1.Range("D" & LastRow - 1).Value + 1
End If

Me.txt_ClientID = Left(txt_First, 1) & Left(txt_Last, 1) & txt_Key

My concern is that the sheet being read can/will be sorted. This means that the data being read in the Key column will not stay in sequential order, resulting in duplicate key codes.

What I'd like to do is, have the code search through columns D, E and F to identify the instance with the same initials, and add 1 to the unique value.

[TABLE="class: grid, width: 600"]
<tbody>[TR]
[TD]Today[/TD]
[TD]Updated[/TD]
[TD]Status[/TD]
[TD]Key[/TD]
[TD]Client ID[/TD]
[TD]First[/TD]
[TD]Last[/TD]
[TD]Suffix[/TD]
[TD]Desired Client ID[/TD]
[/TR]
[TR]
[TD]12/28/17[/TD]
[TD]12/02/17[/TD]
[TD]Active[/TD]
[TD]1[/TD]
[TD]RB1[/TD]
[TD]Rob[/TD]
[TD]Burns[/TD]
[TD]Sr.[/TD]
[TD]RB1[/TD]
[/TR]
[TR]
[TD]12/28/17[/TD]
[TD]12/27/17[/TD]
[TD]Active[/TD]
[TD]2[/TD]
[TD]QJ2[/TD]
[TD]Quincy[/TD]
[TD]Jones[/TD]
[TD][/TD]
[TD]QJ1[/TD]
[/TR]
[TR]
[TD]12/28/17[/TD]
[TD]12/29/17[/TD]
[TD]Active[/TD]
[TD]3[/TD]
[TD]RB3[/TD]
[TD]Renee[/TD]
[TD]Burns[/TD]
[TD][/TD]
[TD]RB2[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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