Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Macro to sort numeric rows left to right

I need to create a macro to sort 659 rows by 46 columns. The rows contain
numeric values that need to be sorted for lowest (left) to highest (right).
When I sort manually left to right, the values for every row are not sorted
correctly.

Additionally when I sort manually, the left column in some rows are blank.
This is a spreadsheet that has cells that have been manually updated.

Macro below

Sub SortLefttoRight()
'
' SortLefttoRight Macro
' Macro recorded 12/1/2007 by Carlton A. Barlow
'

'
Range("G15:AZ673").Select
Range("AZ673").Activate
Selection.Sort Key1:=Range("G15"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
End Sub

All help is greatly appreciated

  #2   Report Post  
Posted to microsoft.public.excel.misc
D. D. is offline
external usenet poster
 
Posts: 53
Default Macro to sort numeric rows left to right

Range("G15:AZ673").Sort Key1:=Range("G15"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal
End Sub
is column G the primary column?
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Macro to sort numeric rows left to right

Column G should be the lowest value when sorting is complete.

"D." wrote:

Range("G15:AZ673").Sort Key1:=Range("G15"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal
End Sub
is column G the primary column?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to sort numeric rows left to right

This worked on a smaller test range.

Sub SortLefttoRight()
'
' SortLefttoRight Macro
' Macro recorded 12/1/2007 by Carlton A. Barlow
'

'
Range("G15:O31").Select
For Each cell In Range("G15:G31")

Selection.Sort Key1:=Range("G15"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
Next
End Sub


Gord Dibben MS Excel MVP

On Sun, 2 Dec 2007 06:01:01 -0800, Carlton A. Barlow
wrote:

Column G should be the lowest value when sorting is complete.

"D." wrote:

Range("G15:AZ673").Sort Key1:=Range("G15"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal
End Sub
is column G the primary column?


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Macro to sort numeric rows left to right

Gord,

I modified your macro to include my range and when I run the macro it just
loops and never finishes. Also none of the cells in the range are sorted
correctly. The modifications I made are below.

Range("G15:AZ673").Select
For Each cell In Range("G15:AZ673")
Selection.Sort Key1:=Range("G15"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
Next
End Sub

"Gord Dibben" wrote:

This worked on a smaller test range.

Sub SortLefttoRight()
'
' SortLefttoRight Macro
' Macro recorded 12/1/2007 by Carlton A. Barlow
'

'
Range("G15:O31").Select
For Each cell In Range("G15:G31")

Selection.Sort Key1:=Range("G15"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
Next
End Sub


Gord Dibben MS Excel MVP

On Sun, 2 Dec 2007 06:01:01 -0800, Carlton A. Barlow
wrote:

Column G should be the lowest value when sorting is complete.

"D." wrote:

Range("G15:AZ673").Sort Key1:=Range("G15"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal
End Sub
is column G the primary column?





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to sort numeric rows left to right

Note the For Each range in my version is one column only.

Select the range to sort G15:AZ673 but the sort key is column G

You must change your For Each range to

For Each cell In Range("G15:G673")


Gord

On Sun, 2 Dec 2007 11:15:00 -0800, Carlton A. Barlow
wrote:

Gord,

I modified your macro to include my range and when I run the macro it just
loops and never finishes. Also none of the cells in the range are sorted
correctly. The modifications I made are below.

Range("G15:AZ673").Select
For Each cell In Range("G15:AZ673")
Selection.Sort Key1:=Range("G15"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
Next
End Sub

"Gord Dibben" wrote:

This worked on a smaller test range.

Sub SortLefttoRight()
'
' SortLefttoRight Macro
' Macro recorded 12/1/2007 by Carlton A. Barlow
'

'
Range("G15:O31").Select
For Each cell In Range("G15:G31")

Selection.Sort Key1:=Range("G15"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
Next
End Sub


Gord Dibben MS Excel MVP

On Sun, 2 Dec 2007 06:01:01 -0800, Carlton A. Barlow
wrote:

Column G should be the lowest value when sorting is complete.

"D." wrote:

Range("G15:AZ673").Sort Key1:=Range("G15"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight,
_
DataOption1:=xlSortNormal
End Sub
is column G the primary column?




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
Sort Left-Right & Up-Down Ben Dummar Excel Worksheet Functions 0 April 4th 07 05:56 PM
How do I create a Macro to sort data and insert blank rows & subto karinmpfa Excel Worksheet Functions 2 April 25th 06 09:57 PM
sorting alpha numeric list by first left digit kaduna New Users to Excel 6 January 13th 06 11:10 PM
Sort Macro to Exclude Blank Rows? ScottPcola Excel Worksheet Functions 1 January 5th 06 07:10 PM
Sort Left to Right David Excel Discussion (Misc queries) 1 February 3rd 05 03:18 PM


All times are GMT +1. The time now is 03:50 AM.

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"