Assign Unique ID, After Data Sorts

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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.

TodayUpdatedStatusKeyClient IDFirstLastSuffixDesired Client ID
12/28/1712/02/17Active1RB1RobBurnsSr.RB1
12/28/1712/27/17Active2QJ2QuincyJonesQJ1
12/28/1712/29/17Active3RB3ReneeBurnsRB2

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,540
Members
449,038
Latest member
Guest1337

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