+ Reply to Thread
Results 1 to 5 of 5

Sorting 2 alphanumeric columns using macro - considers only first 4 byte of column

  1. #1
    Registered User
    Join Date
    09-20-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    10

    Sorting 2 alphanumeric columns using macro - considers only first 4 byte of column

    Hello,
    I want to sort data based on first 2 columns(i.e. 1st column is primary key and 2nd column is secondary key). Column is alphanumeric field(will have combined value of alphabets and numeric).
    My macro(below mentioned) is partially(it considers only first 4 byte of column)
    working
    ----------------------------------
    Sub SORT()
    Cells.Select
    Selection.SORT Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
    , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
    :=xlSortNormal
    Range("A2").Select
    End Sub
    ----------------------------------
    Questions:
    1. why it is not considering rest of data in column.(PFA data sample)

    Can you help me on this
    Attached Files Attached Files

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Sorting 2 alphanumeric columns using macro - considers only first 4 byte of colum

    I'm confused, what do you think isn't sorting correctly?

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    09-20-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Sorting 2 alphanumeric columns using macro - considers only first 4 byte of colum

    It is sorting like below
    EN02
    EN10
    EN10
    EN10
    EN10
    EN1111
    EN123
    EN171
    EN22
    EN3333
    EN55
    EN554
    EN565

    But it is supposed to be like below
    EN02
    EN10
    EN10
    EN10
    EN10
    EN22
    EN55
    EN123
    EN171
    EN554
    EN565
    EN1111
    EN3333

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Sorting 2 alphanumeric columns using macro - considers only first 4 byte of colum

    If the values were numeric you would be right but text values sort differently.

    You might want to have a read of this: http://www.mvps.org/dmcritchie/excel/sorting.htm

    Dom

  5. #5
    Registered User
    Join Date
    09-20-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    10

    Smile Re: Sorting 2 alphanumeric columns using macro - considers only first 4 byte of colum

    Thanks for the suggestion.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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