View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Excel 2000 VBA Sort without Select

Matt,

The problem is that the Range in Key1 points to the ActiveSheet,
not the Accum sheet. Try rewriting the code as follows.

With Sheets("Accum")
.Range("A2").CurrentRegion.Sort Key1:=.Range("A2"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
End With


Note the period before both Range("A2") references.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Matt." wrote in message
...
Hi all!

I've changed my sort code to as follows. Now I'm getting an

error that
states:
The sort reference is not valid. Make sure that it's within

the data you
want to sort, and the first Sort By box isn't the same or

blank.

Sheets("Accum").Range("A2").CurrentRegion.Sort

Key1:=Range("A2"),
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,

Orientation:=xlTopToBottom

Again, any help greatly appreciated. Worksheet setup still the

same.

Thanks again for any help.

cheers,
Matt.


"Matt." wrote in message
...
Hi all!

If it is possible, can somebody give me the syntax for

sorting a worksheet
without selecting it?

The worksheet has a header row (row 1). I would like to sort

all the
values
in the worksheet by column A Ascending. Column A is a Date.

There will
never be more than 50 rows and 10 columns.

This is the code I'm using.

Sheets("Accum").CurrentRegion.Sort Key1:=Range("A2"),
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,

Orientation:=xlTopToBottom

The error I'm getting is the method or object isn't

supported.

Any help greatly appreciated. Thanks in advance.

cheers,
Matt.