ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Require assist with VBA semantic regarding worksheet selection (https://www.excelbanter.com/excel-programming/314364-require-assist-vba-semantic-regarding-worksheet-selection.html)

Jeff Stryer

Require assist with VBA semantic regarding worksheet selection
 
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

Harald Staff

Require assist with VBA semantic regarding worksheet selection
 
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

"Jeff Stryer" skrev i melding
om...
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




Jeff Stryer

Require assist with VBA semantic regarding worksheet selection
 
Harald - You are my hero. Thanks for taking time to reply.

Best Wishes
Jeff



"Harald Staff" wrote in message ...
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

"Jeff Stryer" skrev i melding
om...
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



All times are GMT +1. The time now is 07:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com