ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run VBA sort when I open worksheet (https://www.excelbanter.com/excel-discussion-misc-queries/224741-run-vba-sort-when-i-open-worksheet.html)

JSnow

Run VBA sort when I open worksheet
 
I've looked all around this wonderful web and I can't find anything on
executing VBA code when a specific worksheet is opened. There's plenty on
opening the workBOOK but I don't need that. What I'd like to do is have a
sheet automatically sort itself when it's opened.

Sheet name: "Half Payout" or "Sheet2"

sorting code: Range("B3:J99").sort Key1:=Range("D3"), Order1:=xlAscending,
Key2:=Range( _
"F3"), Order2:=xlAscending, Key3:=Range("B3"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

Thanks for any help on this.

Gary''s Student

Run VBA sort when I open worksheet
 
Private Sub Worksheet_Activate()
' put your code here
End Sub

Put this in the worksheet code area.
--
Gary''s Student - gsnu200839


"JSnow" wrote:

I've looked all around this wonderful web and I can't find anything on
executing VBA code when a specific worksheet is opened. There's plenty on
opening the workBOOK but I don't need that. What I'd like to do is have a
sheet automatically sort itself when it's opened.

Sheet name: "Half Payout" or "Sheet2"

sorting code: Range("B3:J99").sort Key1:=Range("D3"), Order1:=xlAscending,
Key2:=Range( _
"F3"), Order2:=xlAscending, Key3:=Range("B3"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

Thanks for any help on this.


JSnow

Run VBA sort when I open worksheet
 
Thanks, GS! I knew it would be something simple like that.

"Gary''s Student" wrote:

Private Sub Worksheet_Activate()
' put your code here
End Sub

Put this in the worksheet code area.
--
Gary''s Student - gsnu200839


"JSnow" wrote:

I've looked all around this wonderful web and I can't find anything on
executing VBA code when a specific worksheet is opened. There's plenty on
opening the workBOOK but I don't need that. What I'd like to do is have a
sheet automatically sort itself when it's opened.

Sheet name: "Half Payout" or "Sheet2"

sorting code: Range("B3:J99").sort Key1:=Range("D3"), Order1:=xlAscending,
Key2:=Range( _
"F3"), Order2:=xlAscending, Key3:=Range("B3"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

Thanks for any help on this.



All times are GMT +1. The time now is 01:46 AM.

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