Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sort Issue | Excel Discussion (Misc queries) | |||
SORT/FILTER ISSUE | Excel Worksheet Functions | |||
Sort issue | Excel Worksheet Functions | |||
sort issue | Excel Programming | |||
Sort issue | Excel Programming |