ArcMap Tip: Unique Numbers Your Way
ArcMap Tip: Unique Numbers Your Way
A couple of weeks ago I got asked a question. I thought I'd post the question and my response here for the benefit of others.
Question:
In ArcMap, how do you add a unique numerical identifier to features in the order that you want them (i.e., not in the order of the FID field and without endlessly typing one number after another)?
Answer:
Use this handy-dandy VBA script in the field calculator, of course! Here's how:
- In ArcMap, open the table of the layer you wish to auto-num
- If there is not already a field to store your numbers in, add a new numberical field (i.e. ID_NUM)
- Sort your database in the order that you would like the numbers to appear and/or select the records you wish to number
- Right-click on the field's header for the pop-up menu and choose Field Calculator
- Click on the Advance option (in the middle of the Field Calculator tab)
- Type or copy/paste the following into the Pre-Logic VBA Script Code box:
Static rec As Long
Dim lStart As Long
Dim lInterval As Long
lStart = 0
lInterval = 1
If (rec = 0) Then
rec = lStart
End If
rec = rec + lInterval
- In the box below that, type in rec
- Click OK
Voila!

