Results 1 to 7 of 7

Thread: How to Sort This Data

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    52

    Arrow How to Sort This Data

    hello guys..

    I have a problem in sorting the excel data in VB..This is example of the data:

    PAP03-101-108-01-00-00-00-0000
    PAP03-101-108-02-00-00-00-0000
    PAP04-101-108-01-01-00-00-0000
    PAP04-101-108-02-01-00-00-0000
    PAP04-101-108-01-02-00-00-0000

    When i try to sort the data, the result is:

    PAP03-101-108-01-00-00-00-0000
    PAP03-101-108-02-00-00-00-0000
    PAP04-101-108-01-01-00-00-0000
    PAP04-101-108-01-02-00-00-0000
    PAP04-101-108-02-01-00-00-0000

    Actually, Im trying to sort it to be in this way :

    PAP03-101-108-01-00-00-00-0000
    PAP04-101-108-01-01-00-00-0000
    PAP04-101-108-01-02-00-00-0000
    PAP03-101-108-02-00-00-00-0000
    PAP04-101-108-02-01-00-00-0000

    I donno how to do it.. I try to use macro code, but nothing happened.
    VB Code:
    1. Dim tmp1, tmp2 As String
    2.  
    3.      tmp1 = "B2"
    4.      tmp2 = "D" & n
    5.      objExcel.Range("tmp1:tmp2").Select
    6.      objExcel.Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("D2") _
    7.         , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    8.         False, Orientation:=xlTopToBottom

    help me guyz!

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: How to Sort This Data

    It is sorting correctly according to text rules.
    If you need to sort differently you'd need a couple of functions to split the cells data into other cells then sort as you require.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    52

    Re: How to Sort This Data

    thanks 4 the reply!

    Am i have to do it in excel form? Or it's better to split it first in the database juz before i display it in excel?

  4. #4
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: How to Sort This Data

    Would it be possible on the Excel Sheet to split "PAP03-101-108-02-00-00-00-0000" into TWO columns ... "PAP03-" in one, and "101-108-02-00-00-00-0000" in the second? If you can do that, things get a lot easier. You can format the first column Right Justified, and the second column Left Justified to make the data easier to read. Of course, someone is going to come along with some other weird format and foul things up!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    52

    Re: How to Sort This Data

    thanks Webtest!

    It works great!!

  6. #6
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: How to Sort This Data

    I was thinking that you might also find some advantage in forcing the right hand column into a number and formatting it:
    Selection.NumberFormat = "0000-00-0000"
    ... but Excel only supports 15 significant digits, and you have 18. Oh well, so much for that brainstorm.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  7. #7
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: How to Sort This Data

    I was thinking that you might also find some advantage in forcing the right hand column into a number and formatting it 'Custom' (manually or programmatically):
    Selection.NumberFormat = "000-000-00-00-00-00-0000"
    ... but Excel only supports 15 significant digits, and you have 18. Oh well, so much for that brainstorm.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

Posting Permissions

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



Click Here to Expand Forum to Full Width