Thread: VBA Sorting
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bruno Campanini[_2_] Bruno Campanini[_2_] is offline
external usenet poster
 
Posts: 74
Default VBA Sorting

Claus Busch explained :
Hi Bruno,

Am Mon, 15 Jun 2015 18:20:48 +0200 schrieb Bruno Campanini:

How do I sort:
101 120 103
4 1 2
15 12 26

into:
1 2 4
12 15 26
101 103 120


try:

Sub Sort()
Dim LRow As Long, i As Long

With Sheets("Sheet1")
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
.Sort.SortFields.Clear
.Range("A1:C" & LRow).Sort Key1:=.Range("A1"), order1:=xlAscending,
Header:=xlNo

For i = 1 To LRow
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Cells(i, 1), _
SortOn:=xlSortOnValues, Order:=xlAscending
With .Sort
.SetRange Rows(i)
.Header = xlNo
.Orientation = xlLeftToRight
.Apply
End With
Next
End With
End Sub


Regards
Claus B.


Ok, thank you.

But let me say I was not very precise in my question: I intended
to get the result with SORT method + its proper parameters,
without coding a time-consuming range scanning.

Bruno