sort macro help

D

dzelnio

Cells.Select
Selection.Sort Key1:=Range("E1"), Order1:=xlDescending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Anyone know why this macro would stop everytime?

dzelnio
 
G

Gord Dibben

Sub foo()
Cells.Select
Selection.Sort Key1:=Range("E1"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Works for me.

What do you mean by "stop"? Any error message or?


Gord Dibben MS Excel MVP
 
D

dzelnio

I might need to refer to the worksheet in the code. It is called
"Details".
How do I make the script select the worksheet called "Details" then do
the sorting?

Dave
 
G

Gord Dibben

If that sheet is not the activesheet then yes...........you must refer to it.

Sub foo()
With Sheets("Details")
Cells.Select
Selection.Sort Key1:=Range("E1"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
End Sub


Gord
 
D

dzelnio

Where syntax error on this script...

Sub Sortdescending()

With Sheets("Details")
Cells.Select
Selection.Sort Key1:=Range("E1"), Order1:=xlDescending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
End Sub

=====
 
D

Dave Peterson

How about:

Sub foo()
With Sheets("Details")
with .usedrange 'column A to whatever?
.cells.sort Key1:=.columns(5), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
end with
end with
End Sub
 
D

dzelnio

The syntax error lands on Sub foo()
??

How about:

Sub foo()
With Sheets("Details")
with .usedrange 'column A to whatever?
.cells.sort Key1:=.columns(5), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
end with
end with
End Sub
 
G

Gord Dibben

Which line is highlighted when you get the error?

That should tell you something.

Works for me as written so don't get any syntax errors to look for.

This line is all one line...........should show in red font if you have it in
your module as two or three lines without a line continuation character as your
post shows

Selection.Sort Key1:=Range("E1"),Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Gord
 
D

Dave Peterson

Delete that line and then retype that line.

You may have extra (invisible) characters that you can't see.
 
D

Dave Peterson

You'd also want to select that worksheet:

With Sheets("Details")
.select
Cells.Select
 
D

Dave Peterson

If details isn't the activesheet, then
cells.select will be selecting the cells on whatever sheet is active.
And selection.sort will be sorting the selection on whatever sheet is active.

But I wouldn't select it either. I'd just make sure every range object is
qualified with worksheets("details").
 
G

Gord Dibben

So right.

I was testing with Details sheet active so did not notice.

It's the new drugs<g>


Gord
 
G

Gord Dibben

The old ones were not much better but I'm sure you will drop that in
somewhere<g>

Gord
 
D

dzelnio

The macro is working for now. It is part of a larger script, so I'll
be testing it for a couple of days...

This process has taken me way too many hours. You guys probably could
have done it in your sleep.

Thanks for the help!

dzelnio
 

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