Require assist with VBA semantic regarding worksheet selection

  • Thread starter Thread starter Jeff Stryer
  • Start date Start date
J

Jeff Stryer

Hello,

I have the following subroutine for sorting a table:

Sheets("Quotes").Range("A5:AB500").Sort Key1:=Range("A5"),
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal

This works fine when I the worksheet in question "Quotes" is
the active worksheet. However, when I invoke this macro while
another worksheet is open, I get an error.

Any assist with this is greatly appreciated.

Thanks
Jeff
 
Hi Jeff

That is because Range("A5") points to the active sheet. Try

Sheets("Quotes").Range("A5:AB500").Sort Key1:=Sheets("Quotes").Range("A5"),
....

HTH. Best wishes Harald
 
Harald - You are my hero. Thanks for taking time to reply.

Best Wishes
Jeff
 

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