View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Susan Susan is offline
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