+ Reply to Thread
Results 1 to 4 of 4

Sort Issue

  1. #1
    Registered User
    Join Date
    02-14-2006
    Posts
    24

    Unhappy Sort Issue

    i have these following data (around 10000 lines or more). I am looking for help with a small program which I can sort the main line and its sublines.

    datafile:

    M 6 Name: ID 32 Duty, Finished
    A
    C
    E
    ========================================
    M 6 Name: ID 1 Duty, Finished
    W
    X
    Y
    Z
    ========================================
    M 6 Name: ID 14 Duty, Finished
    K
    L
    M

    There are no telling how many sublines it may have below the main line (ID line 32,1,14) but it is always start with an M. I need it sort with the result below:

    M 6 Name: ID 1 Duty, Finished
    W
    X
    Y
    Z
    M 6 Name: ID 14 Duty, Finished
    K
    L
    M
    M 6 Name: ID 32 Duty, Finished
    A
    C
    E

    Many thanks!

  2. #2
    Carim
    Guest

    Re: Sort Issue

    Hi tbobo,

    Why don't you take a look at the following post :
    http://groups.google.com/group/micro...df61023e249a1d

    HTH
    Cheers
    Carim


  3. #3
    KC
    Guest

    RE: Sort Issue

    For exercise, try this.
    You have to adjust the number of columns to move please.
    I assumed ONE only

    Sub Macro1()
    Dim rng As Range
    Dim newrng As Range
    Set awf = Application.WorksheetFunction

    If Range("A1").End(xlDown) <> "===" Then
    Range("A1").End(xlDown).Offset(1, 0) = "'==="
    Set rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))

    Range("A1").CurrentRegion.Copy Range("J1")
    Range("J1").CurrentRegion.Sort Key1:=Range("J1")
    Set newrng = Range("J1:J" & Range("J65536").End(xlUp).Row)

    firstrow = newrng.Find("M 6 Name", after:=Range("J1")).Row
    lastrow = newrng.Find("M 6 Name", after:=Range("J1"),
    SearchDirection:=xlPrevious).Row

    tocell = 20000

    For i = firstrow To lastrow
    thisrow = awf.Match(Range("J" & i), rng, 0)
    stoprow = rng.Find("=", after:=Cells(thisrow, 1)).Row
    If tocell = 20000 Then Rows(thisrow & ":" & stoprow - 1).Copy
    Range("A20000")
    If tocell > 20000 Then Rows(thisrow & ":" & stoprow - 1).Copy
    Range("A65536").End(xlUp).Offset(1, 0)
    tocell = tocell + 1
    Next i

    Rows("1:19999").Delete
    Columns("J").Delete
    End Sub

    "tbobo" wrote:

    >
    > i have these following data (around 10000 lines or more). I am looking
    > for help with a small program which I can sort the main line and its
    > sublines.
    >
    > datafile:
    >
    > M 6 Name: ID 32 Duty, Finished
    > A
    > C
    > E
    > ========================================
    > M 6 Name: ID 1 Duty, Finished
    > W
    > X
    > Y
    > Z
    > ========================================
    > M 6 Name: ID 14 Duty, Finished
    > K
    > L
    > M
    >
    > There are no telling how many sublines it may have below the main line
    > (ID line 32,1,14) but it is always start with an M. I need it sort
    > with the result below:
    >
    > M 6 Name: ID 1 Duty, Finished
    > W
    > X
    > Y
    > Z
    > M 6 Name: ID 14 Duty, Finished
    > K
    > L
    > M
    > M 6 Name: ID 32 Duty, Finished
    > A
    > C
    > E
    >
    > Many thanks!
    >
    >
    > --
    > tbobo
    > ------------------------------------------------------------------------
    > tbobo's Profile: http://www.excelforum.com/member.php...o&userid=31530
    > View this thread: http://www.excelforum.com/showthread...hreadid=519993
    >
    >


  4. #4
    Registered User
    Join Date
    02-14-2006
    Posts
    24

    Thank you KC!

    It works great!

+ 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