Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel macro to sort columns, one row at a time

Hi folks

I use macros using the record feature of Excel but dont know vis basic.
I think i need some kind of simple for-loop to systematically go row
by row and sort my columns in ascending order.

It would look something like this.

For Row = 1 to 2000, Step 1
Sort Row Code (see below cutout of actual code for doing just one
row)
Next


I dont know how to write this code to make it increment row by row.
Any help is greatly appreciated!

Vincent

Range("DW2:FR2").Select

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Excel macro to sort columns, one row at a time

vincent - i'm working on it!
:)
just might take me a little bit (no guru here).
didn't want you to think nobody was answering! i'm a relative newbie
myself so it takes me a while to write code..............
maybe some guru will take pity on you & answer you while i'm working on
it!
ha ha
susan


vincent wrote:
Hi folks

I use macros using the record feature of Excel but dont know vis basic.
I think i need some kind of simple for-loop to systematically go row
by row and sort my columns in ascending order.

It would look something like this.

For Row = 1 to 2000, Step 1
Sort Row Code (see below cutout of actual code for doing just one
row)
Next


I dont know how to write this code to make it increment row by row.
Any help is greatly appreciated!

Vincent

Range("DW2:FR2").Select

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Excel macro to sort columns, one row at a time

ok, here you go.......
worked for me...
xxxxxxxxxxxxxxxx
Option Explicit

Sub sortrow()
Dim MyRng As Range
Dim row As Range
Dim wks As Worksheet
Dim Sheet1 As Worksheet

Set Sheet1 = ActiveWorkbook.Worksheets(1)
Set MyRng = Sheet1.Range("DW2:FR2000")

Sheet1.Range("DW2").Select
For Each row In MyRng.Rows
On Error Resume Next
Selection.Sort Key1:=Range("DW2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
ActiveCell.Offset(1, 0).Select
Next row
End Sub
xxxxxxxxxxxxxxxxxxxx
you have to copy & paste this code into a module.
hope it works for you!
susan




vincent wrote:
Hi folks

I use macros using the record feature of Excel but dont know vis basic.
I think i need some kind of simple for-loop to systematically go row
by row and sort my columns in ascending order.

It would look something like this.

For Row = 1 to 2000, Step 1
Sort Row Code (see below cutout of actual code for doing just one
row)
Next


I dont know how to write this code to make it increment row by row.
Any help is greatly appreciated!

Vincent

Range("DW2:FR2").Select

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Excel macro to sort columns, one row at a time

remember when i said i'm not a guru?
it's not working exactly right........ offsets, etc., but is not
sorting anything
except the 1st row.
still working on it.
<sheepishly
susan

Susan wrote:
ok, here you go.......
worked for me...
xxxxxxxxxxxxxxxx
Option Explicit

Sub sortrow()
Dim MyRng As Range
Dim row As Range
Dim wks As Worksheet
Dim Sheet1 As Worksheet

Set Sheet1 = ActiveWorkbook.Worksheets(1)
Set MyRng = Sheet1.Range("DW2:FR2000")

Sheet1.Range("DW2").Select
For Each row In MyRng.Rows
On Error Resume Next
Selection.Sort Key1:=Range("DW2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
ActiveCell.Offset(1, 0).Select
Next row
End Sub
xxxxxxxxxxxxxxxxxxxx
you have to copy & paste this code into a module.
hope it works for you!
susan




vincent wrote:
Hi folks

I use macros using the record feature of Excel but dont know vis basic.
I think i need some kind of simple for-loop to systematically go row
by row and sort my columns in ascending order.

It would look something like this.

For Row = 1 to 2000, Step 1
Sort Row Code (see below cutout of actual code for doing just one
row)
Next


I dont know how to write this code to make it increment row by row.
Any help is greatly appreciated!

Vincent

Range("DW2:FR2").Select

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Excel macro to sort columns, one row at a time

ok, do you hate me yet?
this one works, i promise.........
:)
susan
xxxxxxxxxxxxxxxxxxxxx
Option Explicit

Sub sortrow()
Dim MyRng As Range
Dim row As Range
Dim wks As Worksheet
Dim Sheet1 As Worksheet
Dim aa As Range

Set Sheet1 = ActiveWorkbook.Worksheets(1)
Set MyRng = Sheet1.Range("DW2:FR2000")

Sheet1.Range("DW2").Select
For Each row In MyRng.Rows
On Error Resume Next
Set aa = ActiveCell
If ActiveCell < Empty Then
row.Select
Selection.Sort Key1:=aa, Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight
ActiveCell.Offset(1, 0).Select
End If
Next row
Sheet1.Range("DW2").Select
End Sub
xxxxxxxxxxxxxxxxxxxxxxxxxxxx


Susan wrote:
remember when i said i'm not a guru?
it's not working exactly right........ offsets, etc., but is not
sorting anything
except the 1st row.
still working on it.
<sheepishly
susan

Susan wrote:
ok, here you go.......
worked for me...
xxxxxxxxxxxxxxxx
Option Explicit

Sub sortrow()
Dim MyRng As Range
Dim row As Range
Dim wks As Worksheet
Dim Sheet1 As Worksheet

Set Sheet1 = ActiveWorkbook.Worksheets(1)
Set MyRng = Sheet1.Range("DW2:FR2000")

Sheet1.Range("DW2").Select
For Each row In MyRng.Rows
On Error Resume Next
Selection.Sort Key1:=Range("DW2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
ActiveCell.Offset(1, 0).Select
Next row
End Sub
xxxxxxxxxxxxxxxxxxxx
you have to copy & paste this code into a module.
hope it works for you!
susan




vincent wrote:
Hi folks

I use macros using the record feature of Excel but dont know vis basic.
I think i need some kind of simple for-loop to systematically go row
by row and sort my columns in ascending order.

It would look something like this.

For Row = 1 to 2000, Step 1
Sort Row Code (see below cutout of actual code for doing just one
row)
Next


I dont know how to write this code to make it increment row by row.
Any help is greatly appreciated!

Vincent

Range("DW2:FR2").Select

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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel macro to sort columns, one row at a time

This worked GREAT! Thanks so MUCH!

On Nov 2, 11:32 am, "Susan" wrote:
ok, do you hate me yet?
thisoneworks, i promise.........
:)
susan
xxxxxxxxxxxxxxxxxxxxx
Option Explicit

Sub sortrow()
Dim MyRng As Range
DimrowAs Range
Dim wks As Worksheet
Dim Sheet1 As Worksheet
Dim aa As Range

Set Sheet1 = ActiveWorkbook.Worksheets(1)
Set MyRng = Sheet1.Range("DW2:FR2000")

Sheet1.Range("DW2").Select
For EachrowIn MyRng.Rows
On Error Resume Next
Set aa = ActiveCell
If ActiveCell < Empty Then
row.Select
Selection.SortKey1:=aa, Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlLeftToRight
ActiveCell.Offset(1, 0).Select
End If
Nextrow
Sheet1.Range("DW2").Select
End Sub
xxxxxxxxxxxxxxxxxxxxxxxxxxxx



Susan wrote:
remember when i said i'm not a guru?
it's not working exactly right........ offsets, etc., but is not
sorting anything
except the 1strow.
still working on it.
<sheepishly
susan


Susan wrote:
ok, here you go.......
worked for me...
xxxxxxxxxxxxxxxx
Option Explicit


Sub sortrow()
Dim MyRng As Range
DimrowAs Range
Dim wks As Worksheet
Dim Sheet1 As Worksheet


Set Sheet1 = ActiveWorkbook.Worksheets(1)
Set MyRng = Sheet1.Range("DW2:FR2000")


Sheet1.Range("DW2").Select
For EachrowIn MyRng.Rows
On Error Resume Next
Selection.SortKey1:=Range("DW2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight
ActiveCell.Offset(1, 0).Select
Nextrow
End Sub
xxxxxxxxxxxxxxxxxxxx
you have to copy & paste this code into a module.
hope it works for you!
susan


vincent wrote:
Hi folks


I use macros using the record feature ofExcelbut dont know vis basic.
I think i need some kind of simple for-loop to systematically gorow
byrowandsortmy columns in ascending order.


It would look something like this.


ForRow= 1 to 2000, Step 1
SortRowCode (see below cutout of actual code for doing justone
row)
Next


I dont know how to write this code to make it incrementrowbyrow.
Any help is greatly appreciated!


Vincent


Range("DW2:FR2").Select


Selection.SortKey1:=Range("DW2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal- Hide quoted text -- Show quoted text -


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 Columns of data at the same time, without regard to order. Herc Excel Worksheet Functions 3 September 10th 09 03:54 AM
Excel 2007 calculate time between 2 date/time columns Kevo Excel Discussion (Misc queries) 8 April 25th 09 12:02 AM
macro from columns to rows but adding every time a new line [email protected] Excel Discussion (Misc queries) 2 December 7th 08 08:59 PM
SORT MULTIPLE COLUMNS AT SAME TIME automatically bkunes Excel Worksheet Functions 7 February 21st 08 05:05 PM
Sort macro by same columns Kevin Sprinkel Excel Programming 3 June 3rd 04 07:31 PM


All times are GMT +1. The time now is 06:31 PM.

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"