Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to sort number follow cell accordingly

Hi, everyone!
I need to create macro that can sort numbers as below:
Column : Before
A B C D E F
1 2 3 4 5 6
3 4 5
1 3 4 5
3 5 6
After
A B C D E F
1 2 3 4 5 6
3 4 5
1 3 4 5
3 5 6
which mean same number follow the same column but not necessary follow
column A,B,C.....
Pls help with vba code.Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default How to sort number follow cell accordingly

GeniusIdeas,

You have to evaluate the assumptions in the program (i.e. read the comments
and evaluate the code). Basically, Integers are assumed for the sort, and
the Integers start at 1 and each consecutive value is 1 plus the previous
value. If you are not familiar with the MATCH function, look it up with the
Excel help.

Best,

Matthew Herbert

Sub CustomSortRoutine()
Dim Rng As Range
Dim rngCell As Range
Dim rngTemp As Range
Dim intArrHdr() As Integer
Dim varArr As Variant
Dim varItem As Variant
Dim intCnt As Integer
Dim lngCnt As Long
Dim varMatch As Variant

Application.ScreenUpdating = False

'assumes you are using Integers only
Set Rng = Selection

'create a lookup array and fill it will consecutive
' numbers, starting at 1; assumes Option Base 0
' which is the default setting
ReDim intArrHdr(Rng.Columns.Count - 1)
For intCnt = LBound(intArrHdr) To UBound(intArrHdr)
intArrHdr(intCnt) = intCnt + 1
Next intCnt

'loop through each row of Rng
For lngCnt = 1 To Rng.Rows.Count

'create a temporary range that references the
' entire row
Set rngTemp = Rng.Rows(lngCnt)

'load the current row's values into an array
varArr = rngTemp.Value

'clear the temporary range
rngTemp.Clear

'loop through each item in the array
For Each varItem In varArr

'match the varItem with intArrHdr. If a match exists,
' offset the value to the appropriate position in the
' row. (If no match, do nothing).
varMatch = Application.Match(varItem, intArrHdr, 0)

If Not IsError(varMatch) Then

'offset from the far-left cell of the row, placing
' the matching value into the offset cell
rngTemp.Cells(1, 1).Offset(0, varMatch - 1).Value = varItem
End If

Next varItem

Next lngCnt

End Sub


"geniusideas" wrote:

Hi, everyone!
I need to create macro that can sort numbers as below:
Column : Before
A B C D E F
1 2 3 4 5 6
3 4 5
1 3 4 5
3 5 6
After
A B C D E F
1 2 3 4 5 6
3 4 5
1 3 4 5
3 5 6
which mean same number follow the same column but not necessary follow
column A,B,C.....
Pls help with vba code.Thanks
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to sort number follow cell accordingly

Thank matthew..Its work fine
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
Getting a hyperlink to follow a sort Andybanker Excel Discussion (Misc queries) 7 June 26th 06 07:39 PM
Formatting doesn't follow data sort kanimalhouse Excel Discussion (Misc queries) 1 September 7th 05 11:16 PM
when you sort named cells, the names do not follow the values Claude38 Excel Discussion (Misc queries) 1 August 16th 05 10:43 PM
Sort order for characters & symbols - does anything follow z? Neil Goldwasser Excel Discussion (Misc queries) 4 August 5th 05 05:02 AM
(Follow-up to earlier sort question) Further help required scottwilsonx[_53_] Excel Programming 0 October 5th 04 03:53 PM


All times are GMT +1. The time now is 08:43 PM.

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

About Us

"It's about Microsoft Excel"