VBA Sorting
How do I sort:
101 120 103 4 1 2 15 12 26 into: 1 2 4 12 15 26 101 103 120 Bruno |
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 |
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 |
All times are GMT +1. The time now is 04:45 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com