Insert a Sequence Number

am465

New Member
Joined
Nov 11, 2013
Messages
2
I would like to insert a sequence number into a query that currently returns 7367 rows.

Here's what it looks like now:

ID_NUM
DTE_FIN_TRANS_RCV
13229/27/2012
13227/10/2012
10117/2/1999
10119/22/1999
101110/21/1999

<tbody>
</tbody>

Here's the desired outcome with sequences:

ID_NUM
DTE_FIN_TRANS_RCV
SEQUENCE
13229/27/20121
13227/10/20122
10117/2/19991
10119/22/19992
101110/21/19993

<tbody>
</tbody>

All I need is a way to number rows with a value higher than the previous for that particular ID_NUM. Any assistance with achieving this will be most appreciated. Thank you.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
am465,

How about something like this:


Excel 2007
ABC
1ID_NUMDTE_FIN_TRANS_RCVSEQUENCE
213229/27/20121
313227/10/20122
410117/2/19991
510119/22/19992
6101110/21/19993
7
Sheet1


The formula in cell C2, copied down:
=COUNTIF($A$2:A2,A2)
 
Upvote 0
am465,

I assume that your raw data is already sorted/grouped by the data in column A, per your example.

Or, with a macro:

Sample raw data:


Excel 2007
ABC
1ID_NUMDTE_FIN_TRANS_RCVSEQUENCE
213229/27/2012
313227/10/2012
410117/2/1999
510119/22/1999
6101110/21/1999
7
Sheet1


After the macro:


Excel 2007
ABC
1ID_NUMDTE_FIN_TRANS_RCVSEQUENCE
213229/27/20121
313227/10/20122
410117/2/19991
510119/22/19992
6101110/21/19993
7
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub InsertSequenceNumber()
' hiker9, 11/11/2013
' http://www.mrexcel.com/forum/microsoft-access/738615-insert-sequence-number.html
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
With Range("C2:C" & lr)
  .Formula = "=COUNTIF($A$2:A2,A2)"
  .Value = .Value
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the InsertSequenceNumber macro.
 
Upvote 0
I tried using a correlated query on this without success (the dreaded "query must be updateable" message). That leaves iterating a recordset which is a little awkward though not terribly difficult.

Is it absolutely necessary. The dates already provide an implicit ordering. What does the sequence numbering provide that you don't already have?

PS:
@Hiker, welcome to the *Access* forum ;)
 
Upvote 0

Forum statistics

Threads
1,214,879
Messages
6,122,065
Members
449,064
Latest member
scottdog129

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