Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Sorting Macro Loop

I have recorded a macro and am playing with it in Visual Basic (excel 2003).
I copy data to a new sheet with values only and now I want to sort all the
columns individually to get the valid data to the top and spaces to the
bottom. My macro can do this, coded with the following sort commands but i
think it would be more efficient to run it as a loop condition. My columns
will alway start in Columns("A:A").Select. Can i do something like

Range (Selection, Selection.End(xlToRight)).Select -- starting in column A
then pass this value to the loop variable and sort from column A to the end
of that variable column.



example body of sort commands to turn into loop procedure
Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("B:B").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("C:C").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("D:D").Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


appreciate any ideas,
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Sorting Macro Loop

Thanks for the help guys, but this one is exactly what i am looking for. It
works great for what I was trying to do. Thanks again.

"Don Guillett" wrote:

Sub sortINDIVIDUALcolumns()
For i = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
Columns(i).Sort Key1:=Cells(2, i), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
'MsgBox i
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"anduare2" wrote in message
...
I have recorded a macro and am playing with it in Visual Basic (excel
2003).
I copy data to a new sheet with values only and now I want to sort all the
columns individually to get the valid data to the top and spaces to the
bottom. My macro can do this, coded with the following sort commands but
i
think it would be more efficient to run it as a loop condition. My
columns
will alway start in Columns("A:A").Select. Can i do something like

Range (Selection, Selection.End(xlToRight)).Select -- starting in column
A
then pass this value to the loop variable and sort from column A to the
end
of that variable column.



example body of sort commands to turn into loop procedure
Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("B:B").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("C:C").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("D:D").Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


appreciate any ideas,
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Sorting Macro Loop

All similar but glad to help.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Sub sortINDIVIDUALcolumns()
For i = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
Columns(i).Sort Key1:=Cells(2, i), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
'MsgBox i
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"anduare2" wrote in message
...
I have recorded a macro and am playing with it in Visual Basic (excel
2003).
I copy data to a new sheet with values only and now I want to sort all
the
columns individually to get the valid data to the top and spaces to the
bottom. My macro can do this, coded with the following sort commands but
i
think it would be more efficient to run it as a loop condition. My
columns
will alway start in Columns("A:A").Select. Can i do something like

Range (Selection, Selection.End(xlToRight)).Select -- starting in
column A
then pass this value to the loop variable and sort from column A to the
end
of that variable column.



example body of sort commands to turn into loop procedure
Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("B:B").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("C:C").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:=xlYes,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns("D:D").Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


appreciate any ideas,
Thanks



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 Macro Loop Don Guillett Excel Programming 0 May 27th 09 05:54 PM
Sorting Macro Loop Jacob Skaria Excel Programming 0 May 27th 09 05:48 PM
Sorting Macro Loop Sam Wilson Excel Programming 0 May 27th 09 05:44 PM
Sorting a Loop N1KO Excel Programming 3 November 3rd 08 10:11 AM
Do until loop with use of another macro in loop The Excelerator Excel Programming 9 February 28th 07 02:28 AM


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