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:

  1. In ArcMap, open the table of the layer you wish to auto-num
  2. If there is not already a field to store your numbers in, add a new numberical field (i.e. ID_NUM)
  3. Sort your database in the order that you would like the numbers to appear and/or select the records you wish to number
  4. Right-click on the field's header for the pop-up menu and choose Field Calculator
  5. Click on the Advance option (in the middle of the Field Calculator tab)
  6. 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

  1. In the box below that, type in rec
  2. Click OK

Voila!

 

 

 website by Mccormick & Winter