sorting out columns but only for some rows

S

Sam

Hi,

I would like to create a macros that will sort out the first 5 rows of
my spreadsheet only. The reason for that is that in the middle of my
spreadsheet i have another group of cells that represent a table and I
don't want that one to be sorted.

How can i do that ?

Thx
 
B

Bernie Deitrick

Sam,

Either select just the cells that you want sorted, prior to the sort, or
insert a new row between the tables to prevent them being sorted together.

HTH,
Bernie
MS Excel MVP
 
J

JulieD

Hi Sam

something along these lines

sub sortsome()

Rows("1:5").Sort Key1:=Range("a2"), Order1:=xlAscending, Header:=xlYes,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End sub

where you have a header row (if not, change Header:=xlYes to Header:=xlNo
and A2 to A1) and you want to sort on the value in column A, if not, change
the A to whatever column you want to sort on
 
M

Max

The recorded macro below seems to be able to do the job ..
(Sort by col C - Descending, then by col B - ascending)

Sub Macro2()
Sheets("Sheet1").Select
Rows("1:6").Select
Selection.sort Key1:=Range("C2"), Order1:=xlDescending,
Key2:=Range("B2") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom
Range("A1").Select
End Sub
 
Top