Selecting range question

  • Thread starter Thread starter ToddG
  • Start date Start date
T

ToddG

I have the following code to select a range:

Sheets("TEST").Select
Range("A1:F129").Select

Is there a way to select this range WITHOUT first
selecting the sheet? I'd like to speed up my macro and
thought this would be a good place to start.

I tried:

Sheets("TEST").Range("A1:F129")

and I get an error.

TIA, Todd
 
Todd,

You rarely ever need to select anything: post all your code, and we can give
you some pointers as to how to re-write without using select.

HTH,
Bernie
MS Excel MVP
 
You probably don't need to select any but use
application.goto Sheets("TEST").Range("A1:F129")
 
Hi Bernie,

Here is a simple example:

Sheets("TEST").Select
Range("A1:F129").Select
Selection.Sort Key1:=Range("F2"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
 
Todd,

Sheets("TEST").Range("A1:F129").Sort Key1:=Range("F2"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom


HTH,
Bernie
MS Excel MVP
 
--
Don Guillett
SalesAid Software
(e-mail address removed)
ToddG said:
Hi Bernie,

Here is a simple example:

Sheets("TEST").Select
Range("A1:F129").Select
Selection.Sort Key1:=Range("F2"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
 
try from ANYWHERE.
Sheets("TEST").Range("A1:F129").Sort Key1:=Range("F2"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
 
Todd,

Oops, forgot to fully qualify the key range:

Sheets("TEST").Range("A1:F15").Sort _
Key1:=Sheets("TEST").Range("F2"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom

HTH,
Bernie
MS Excel MVP
 
Should probably be (for sort key)

Sheets("TEST").range("A1:F129").Sort Key1:=sheets("test").Range("F2"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
 
Don,

You forgot the same thing that I did: the key needs to be

Sheets("Test").Range("F2")

if Test is not the activesheet.

Bernie
MS Excel MVP
 
I know. I caught it as just after I touched the send button. Thanks
 
Was JUST going to ask you about that. Works just fine now.
Thanks a million
 

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

Back
Top