The Animal

Active Member
Joined
May 26, 2011
Messages
449
Hi
I have the below macro that that sorts for example ranges A5:CD22 based on B5:B22 sort selection.
How would it look if instead of selecting the specific ranges as above but rather I wanted to sort entire rows 5:22 based on B5:B22 sort selection?
Any help would be great.
Thanks Stephen

Sub TestSort()
ActiveSheet.Unprotect
Range("A5:CD22").Sort Range("B5:B22"), Order1:=xlAscending, Header:=xlNo
Range("A30:CD35").Sort Range("B30:B35"), Order1:=xlAscending, Header:=xlNo
Range("A46:CD58").Sort Range("B46:B58"), Order1:=xlAscending, Header:=xlNo
Range("A66:CD85").Sort Range("B66:B85"), Order1:=xlAscending, Header:=xlNo
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowFiltering:=True
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Nest this in your unprotect-protect stuff. I should do what I think you question described, not sure how it relates to the code you posted though.

Rows("5:22").Sort Key1:=Range("b2"), Order1:=xlAscending, Header:=xlNo


I hope this helps.

Ken
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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