+ Reply to Thread
Results 1 to 16 of 16

Sequence numbers based on date and independent of column sort order

  1. #1
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Post Sequence numbers based on date and independent of column sort order

    Hi,

    I set up an auto sequence number (column B) based on the date entries in column A (see example below) using the following formula:
    =IF(ISBLANK(A45),"","PERM"&"_"&TEXT(A45,"YYYYMMDD")&"_"&TEXT(COUNTIF($A$5:A45,A45),"0"))

    It all works fine, until I start to re-sort the data entries by the various columns. Then, an entry that had previously assigned sequence number PERM_YYYYMMDD_3 maybe suddenly become PERM_YYYYMMDD_1.

    Is there a formula that will allow me to assign a permanent unique sequential number independent of the sort order?

    Column A Column B
    12/02/2014 PERM_20140212_1
    12/02/2014 PERM_20140212_2
    12/02/2014 PERM_20140212_3

    Thanks so much for your help!
    Barbara

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Sequence numbers based on date and independent of column sort order

    Is it something like this?

    =A2&"_"&COUNTIF($A$2:A2,A2)


    A
    B
    2
    PERM_20140212 PERM_20140212_1
    3
    PERM_20140212 PERM_20140212_2
    4
    PERM_20140212 PERM_20140212_3
    5
    PERM_20140212 PERM_20140212_4
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sequence numbers based on date and independent of column sort order

    Hi AlKey,

    yes, that's the formula I've been using, and the sequential numbers change according to the sort order of the column, but I want them to stay the same once they've been assigned independent of sort order.
    Thanks,
    Barbara

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Sequence numbers based on date and independent of column sort order

    I guess I din't read carefully "permanent unique sequential number". A side from copy and paste back Special, Values will make them permanent, most likely you will need a VBA solution.

  5. #5
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sequence numbers based on date and independent of column sort order

    ok, do I need to re-post this in part of the forum that deals with VBA?

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Sequence numbers based on date and independent of column sort order

    No, I posted this to other. Someone will step in to help you.

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sequence numbers based on date and independent of column sort order

    Please right-click the worksheet tab, then select 'View Code' and then paste this code:
    Please Login or Register  to view this content.
    You must save the workbook as macro-enabled file (.xlsm, .xlsb, or .xls type).
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  8. #8
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sequence numbers based on date and independent of column sort order

    Hi Izandol,

    thanks for getting back to me. I did as instructed, i.e. pasted code, saved as macro-enabled file, but I'm not sure if something's happening in the sheet. I apologize, I'm not too familiar with VBA programming. Do I need to do anything else apart from the above? Does this VBA code replace all the formulas I had been using previously, and do I need to delete them off my sheet? Sorry again and thanks for any further assistance, Barbara

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Sequence numbers based on date and independent of column sort order

    Now you have to run this code. Press Alt+F8 and you should see Macro, click Run.

  10. #10
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sequence numbers based on date and independent of column sort order

    I tried (both by Alt+F8 and by going via Developer to the Macros tab), but the window is empty, there are no macros listed for this workbook.

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sequence numbers based on date and independent of column sort order

    This is not macro - it is event code. When you enter new dates in column A it will automatically create sequence in column B. For existing data you may copy and paste special - values to change your formulas for fixed values.

  12. #12
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Sequence numbers based on date and independent of column sort order

    Please right-click the worksheet tab, then select 'View Code' and then paste this code:
    If you have followed Izandol suggestions the code will be found behind the worksheet itself (right click, view code) rather than in the workbook modules area.

    Once you can see the code in the VB editor, put a break point at the first "If" statement to allow you to step throught he code one instruction at a time. Go back to the worksheet and enter a new date in Col A and the event should trigger the code and stop at the break.

    Sorry if this is sounding a bit "101" but with 7 posts to the forum you may not know how some of this actually works

    Hope this helps
    Last edited by jmac1947; 02-21-2014 at 01:38 AM. Reason: spelling typos

    Cheers

    Jmac1947

    1. Please consider clicking on the * Add Reputation if you think this post has helped you
    2. Mark your thread as SOLVED when question is resolved

  13. #13
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sequence numbers based on date and independent of column sort order

    thanks jmac1947, that will help.

    I still need to figure out how to create the sequential number in column Q, and not B. Any idea how the code needs to be changed? I haven't really figured out how the R1C1 reference style works.

    Thanks so much!
    B

  14. #14
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sequence numbers based on date and independent of column sort order

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    02-18-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Sequence numbers based on date and independent of column sort order

    thanks Izandol, that works. I'm afraid I need to bug you one more time as I realized that the sequencing only works when I fill in the dates a descending order, but not in a random order.

    For example, if I have forgotten to add an item at a particular date, and want to add it later on by inserting a row above, it won't assign the next following sequence number. Is there a way to make the system recognize that there are already items for the same date no matter in which row they are?

    Thanks,
    Barbara

  16. #16
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Sequence numbers based on date and independent of column sort order

    Perhaps try:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 03-14-2013, 09:14 PM
  2. Macro to Autofill down numbers in Sequence order.
    By awagenhurst in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2013, 07:57 AM
  3. [SOLVED] Creating a sequence based on numbers in one column and adding "01,02..." to a new sequence
    By JCR1968 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2013, 08:06 AM
  4. How to Move Worksheets based on Sort Order Column
    By AdamParker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2011, 03:09 PM
  5. sort column in date order dd/mm/yy
    By K in forum Excel General
    Replies: 4
    Last Post: 04-13-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1