Possible using VBA to sort a Non-Active Sheet?

keithmcvean

New Member
Joined
Dec 20, 2013
Messages
13
I have a macro tied to a button on a sheet called "Programs". As part of the code of this it sorts a named range "Setting_Employees" on a separate sheet called "Settings".

Ideally, to keep the macro from flipping around the active sheets I was hoping to sort a non-selected, non-active sheet. So far I haven't been able to make this work.

This code works but, as I said, I was hoping to do this without making the Settings sheet active. Is it possible?

Worksheets("Settings").Select
Range("Setting_Employees").Sort Key1:=Range("Setting_Employees").Cells(1, 1), _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

Thanks in advance,
Keith
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Why don't you just make the sheet you started on active again at the end of the code?

Maybe turn screen updating OFF so you don't see it changing sheets visually.
 
Last edited:
Upvote 0
Or try this
Rich (BB code):
Worksheets("Settings").Range("Setting_Employees").Sort Key1:=Range("Setting_Employees").Cells(1, 1), _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top