View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default macro code to sort a range

Sub gsnu()
Sheets("a").Select
Range("C2:H30").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

--
Gary''s Student


"ashish128" wrote:

Hello All,
I tried searching in the group but found nothing of what I was
looking for.
I have a .xls file with 10 worksheets in it. assume that sheets are
named as a,b,c,d to j. I am trying to make a macro which will sort a
range c2:h30 on sheet "a" then range c2:h15 on sheet "b" then range
c2:h45 on sheet "c" and so on.[ I know exact range for each sheet so
nothing is required to be calculated dynamically and also the sorting
will be based upon the cell h2]. I dont want to use loop because I
would like to skip some sheets some times. If any one can tell me how
to write this macro then I will be highly grateful to him. Teach me for
one sheet and I will apply best of my mind to make it work for others
too.
Thanks for listening (or reading so long).