+ Reply to Thread
Results 1 to 7 of 7

Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

  1. #1
    Registered User
    Join Date
    12-17-2013
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2010
    Posts
    1

    Question Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    Hello Folks,

    I am trying to create a VBA macro to sort data in a spreadsheet in the following order:
    1,2,3,4
    1,2,3,4
    1,2,3,4
    5,6

    Rather than the traditional 111,222,333,444,5,6 that you get through the normal Sort options.

    Thank you in advance,

    John

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    Can you upload a workbook with an example of how the data is laid out and hwo you want the results to be arranged. Click go advanced and then manage attachments to upload a workbook.

    Also how would 11122233344455666777888899 be sorted?

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    I presume your data is in one column, but it is confusing how you have laid it out in your description.

    I would suggest having a helper column with a formula like:

    =COUNTIF(A$1:A1,A1)

    so when you copy this down then an "occurrence" number is generated. Then you want to sort using this as the key field and the other numbers as the secondary field.

    Hope this helps.

    Pete

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    @ Pete I originally thought along those lines but think that would give 12345612341234 not 12341234123456... Maybe sort by the helper column descending and then by the number column ascending might work? I'm not sure what OP wants...

  5. #5
    Registered User
    Join Date
    08-18-2011
    Location
    Warrington, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    Hi Guys,

    Thank you so much for your input so far. Please see a workbook showing how the data currently is, and how i want it to be.

    John
    example.xlsx

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    Hi John,
    maybe so
    Please Login or Register  to view this content.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Sort data 1,2,3,4 1,2,3,4 NOT 1,1,2,2,3,3,4,4

    Put this formula in C2:

    =IF(LEFT(A2)*1>4,1000+ROWS($1:1),COUNTIF(A$2:A2,A2))

    then copy down to the bottom of your data. Then sort using column C as the first sort field and column A as the second sort field. Then you can delete column C.

    Hope this helps.

    Pete

+ 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. [SOLVED] How to sort the data by item code first, then sort them by date?
    By Zecond in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-04-2013, 01:55 AM
  2. Replies: 4
    Last Post: 11-20-2012, 06:00 PM
  3. [SOLVED] Pls. reply Sort Data and copy to next coulmn when sort order chang
    By shital shah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2005, 10:05 AM
  4. [SOLVED] Sort Data and copy to next coulmn when sort data changes
    By shital shah in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2005, 02:05 AM
  5. Replies: 1
    Last Post: 03-17-2005, 08:06 PM

Tags for this Thread

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