#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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!


--
tbobo
------------------------------------------------------------------------
tbobo's Profile: http://www.excelforum.com/member.php...o&userid=31530
View this thread: http://www.excelforum.com/showthread...hreadid=519993

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Sort Issue

Hi tbobo,

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

HTH
Cheers
Carim

  #3   Report Post  
Posted to microsoft.public.excel.programming
KC KC is offline
external usenet poster
 
Posts: 107
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sort Issue


It works great!


--
tbobo
------------------------------------------------------------------------
tbobo's Profile: http://www.excelforum.com/member.php...o&userid=31530
View this thread: http://www.excelforum.com/showthread...hreadid=519993

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort Issue Texins Karate Excel Discussion (Misc queries) 2 December 14th 09 06:16 PM
SORT/FILTER ISSUE Munfarid Excel Worksheet Functions 4 September 11th 09 03:54 AM
Sort issue Patrick C. Simonds Excel Worksheet Functions 1 December 30th 07 11:37 AM
sort issue Shawn Excel Programming 9 September 23rd 06 06:56 PM
Sort issue Patty[_2_] Excel Programming 9 December 12th 03 09:47 PM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"