Macro Help

J

JimS

I'm a complete newbie when it comes to macros.

H I J K
422 11 2.0 1.6 0.40
423 5 4.0 3.5 0.50
424 7 6.0 4.0 2.00

I highlighted this group of numbers in my spread sheet from H422 to K
424, and then I recorded a macro to sort on column K from highest to
lowest. When done it looks like this:

7 6.0 4.0 2.00
5 4.0 3.5 0.50
11 2.0 1.6 0.40

I want this macro to work for every group of numbers like this
throughout the spread sheet. Not all at once, but one at a time as I
need them. So if I go down to row 464 and try to run the macro on a
similar group of numbers it doesn't work.

Where am I going wrong?

Thanks
 
D

Don Guillett

Sub sortselectionSAS()
With Selection
.Sort Key1:=.Cells(1, 1), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End With
End Sub
 
J

JimS

Hi and thanks for the help, but I don't think it's working. I
recorded the macro again, and this is the code it produced:

Sub Odds()
'
' Odds Macro
'
' Keyboard Shortcut: Ctrl+o
'
Range("H422:K424").Select
ActiveWorkbook.Worksheets("Louie 5").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Louie 5").Sort.SortFields.Add
Key:=Range( _
"K422:K424"), SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Louie 5").Sort
.SetRange Range("H422:K424")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

I "think" what I need to do is to be able to select my own range which
will always be the same size--if that matters.
 
D

Don Guillett

My macro was written using xl2003. I just tested in xl2007 and it worked
properly. A sort macro written in xl2007 will not work in xl2003.

if I select the range you show below and fire the macro it sorts that range
by the first column in the selection.
If desired, send your file to my address below. I will only look if:
1. You send a copy of this message on an inserted sheet
2. You give me the newsgroup and the subject line
3. You send a clear explanation of what you want
4. You send before/after examples and expected results.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top