Thread: VBA Sorting
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default VBA Sorting

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.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional