Can I exclude a column when sorting with VBA

Needinghlp

New Member
Joined
Feb 27, 2013
Messages
25
Hi everyone, I am using the code below to conduct a sort and I wondered if it is possible to exclude a column when sorting i.e. could I exclude column R from the sort so that it remains as is. I have been looking for similar questions and it appears maybe this isn't possible but just wanted to put the question out there in case I've missed the answer. Many thanks.

Private Sub CommandButton1_Click()
'vba_sort_range()
Range("a3:AA1021").Sort Key1:=Range("x3"), _
Order1:=xlDescending, _
Key2:=Range("q3"), _
Order2:=xlDescending, _
Header:=xlNo
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Not quite sure why you would want to do that, but it's not possible.
 
Upvote 0
If you are sorting either side of column "R", which it appears you are....why would you want to exclude a column ??
That would make the data invalid, as the rows would be misaligned !!
Otherwise, short answer is No, you can't
 
Upvote 0
Just move column R to column AB outside your sort range

Or do 2 sorts a:q and s: aa
 
Upvote 0
@rhombus4 as the 1st sort key is col X you cannot do two sorts as you have suggested.
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

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