#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
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
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
SORTING DATA IN TWO COLUMNS (salary and name ) - sorting as perdescending order of salary [email protected] Excel Programming 0 July 26th 13 09:53 AM
Sorting Values Without Sorting Formulas SBX Excel Discussion (Misc queries) 2 April 12th 09 11:17 PM
Automatic sorting (giving max and min) based on custom sorting lis Joe Lewis[_2_] Excel Worksheet Functions 4 November 23rd 08 05:12 AM
Sorting VLookup vs Sorting SumProduct Lauren Excel Discussion (Misc queries) 1 August 21st 07 12:19 AM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


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