Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Sort and Transpose

I can do this with in the worksheet, but i'd like to do the same with
in VB


Starting with date and numberic values in separate cells in multiple
rows
2/2/2008 1 11/1/2007 12 7/1/2007 1 4/1/2007 2
1/1/08 10 10/1/2007 4 6/1/2007 5 3/1/2007 2
12/1/2007 3 9/1/2007 7


convert above into column
2/2/2008 1
1/1/08 10
12/1/2007 3
11/1/2007 12
10/1/2007 4
9/1/2007 7
7/1/2007 1
6/1/2007 5
4/1/2007 2
3/1/2007 2


sort columns
3/1/2007 2
4/1/2007 2
6/1/2007 5
7/1/2007 1
9/1/2007 7
10/1/2007 4
11/1/2007 12
12/1/2007 3
1/1/08 10
2/2/2008 1


convert above into row, each value in a separate column
2/2/2008 1 1/1/08 10 12/1/2007 3 11/1/2007 12 10/1/2007 4 9/1/2007 7
7/1/2007 1 6/1/2007 5 4/1/2007 2 3/1/2007
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Sort and Transpose

Hi

I think this is what you are looking for with data in A1 and further.

Dim MyAray()
Dim Counter As Long

Sub ReArrangeData()
Range("A1").CurrentRegion.Select
CellCount = Selection.Rows.Count * Selection.Columns.Count
ReDim MyAray(CellCount + 2)
Counter = 0
For Each c In Selection
MyAray(Counter) = c.Value
Counter = Counter + 1
Next
Selection.Delete
For c = 0 To Counter Step 2
Range("A1").Offset(Off, 0) = MyAray(c)
Range("A1").Offset(Off, 1) = MyAray(c + 1)
Off = Off + 1
Next
Range("A1").CurrentRegion.Sort Key1:=Range("A1"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").CurrentRegion.Select
Off = 0
For Each c In Selection
c.Cut
Range("A1").Offset(0, Off).Select
ActiveSheet.Paste
Off = Off + 1
Next
End Sub

Regards,

Per
"wutzke" skrev i en meddelelse
...
I can do this with in the worksheet, but i'd like to do the same with
in VB


Starting with date and numberic values in separate cells in multiple
rows
2/2/2008 1 11/1/2007 12 7/1/2007 1 4/1/2007 2
1/1/08 10 10/1/2007 4 6/1/2007 5 3/1/2007 2
12/1/2007 3 9/1/2007 7


convert above into column
2/2/2008 1
1/1/08 10
12/1/2007 3
11/1/2007 12
10/1/2007 4
9/1/2007 7
7/1/2007 1
6/1/2007 5
4/1/2007 2
3/1/2007 2


sort columns
3/1/2007 2
4/1/2007 2
6/1/2007 5
7/1/2007 1
9/1/2007 7
10/1/2007 4
11/1/2007 12
12/1/2007 3
1/1/08 10
2/2/2008 1


convert above into row, each value in a separate column
2/2/2008 1 1/1/08 10 12/1/2007 3 11/1/2007 12 10/1/2007 4 9/1/2007 7
7/1/2007 1 6/1/2007 5 4/1/2007 2 3/1/2007



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
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
I WANT TO TRANSPOSE LINKS, AS WE TRANSPOSE VALUES Umair Aslam Excel Worksheet Functions 1 September 22nd 05 01:19 PM
Pls. reply Sort Data and copy to next coulmn when sort order chang shital shah Excel Programming 1 August 19th 05 02:51 PM
Excel sort by Fill Color by custom list sort Dash4Cash Excel Discussion (Misc queries) 2 July 29th 05 10:45 PM
sort (on part of) string - originally posted under Tricky Sort Tom Ogilvy Excel Programming 0 August 6th 04 02:42 AM


All times are GMT +1. The time now is 12:52 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"