A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

macro code to sort a range



 
 
Thread Tools Display Modes
  #1  
Old August 17th, 2006, 01:42 PM posted to microsoft.public.excel.misc
ashish128
external usenet poster
 
Posts: 30
Default macro code to sort a range

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).

  #2  
Old August 17th, 2006, 02:01 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 7,584
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).


  #3  
Old August 17th, 2006, 02:45 PM posted to microsoft.public.excel.misc
ashish128
external usenet poster
 
Posts: 30
Default macro code to sort a range

Hi,
I modified your code for actual values but on running it gives an
error,

"Run Time Error 1004"
Application defined or object defined error

Following is modified code
Sub gsnu()
Sheets("wax").Select
Range("C2:AN11").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("AK2"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

The Range is found selected when i stop the debugger.

Also can u tell me what is "xlSortNormal" and "matchcase" for and
difference between Order1 and orientation

Gary''s Student wrote:
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).



  #4  
Old August 17th, 2006, 03:01 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 7,584
Default macro code to sort a range

I can't get your error message to appear. The code I posted is a direct copy
of the code generated by the Macro Recorder.
--
Gary's Student


"ashish128" wrote:

Hi,
I modified your code for actual values but on running it gives an
error,

"Run Time Error 1004"
Application defined or object defined error

Following is modified code
Sub gsnu()
Sheets("wax").Select
Range("C2:AN11").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("AK2"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

The Range is found selected when i stop the debugger.

Also can u tell me what is "xlSortNormal" and "matchcase" for and
difference between Order1 and orientation

Gary''s Student wrote:
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).




  #5  
Old August 17th, 2006, 03:22 PM posted to microsoft.public.excel.misc
ashish128
external usenet poster
 
Posts: 30
Default macro code to sort a range

Hi, Thanks
You gave me the Idea. I self imitated the macro recording and found
that instead of "Range("AK2")" I must write "Range("AK3")" to make it
work. I dont know why i had to choose a value cell instead of a header
cell to make it work but as for now it works and all the thanks go to
you. Thanks again

Gary''s Student wrote:
I can't get your error message to appear. The code I posted is a direct copy
of the code generated by the Macro Recorder.
--
Gary's Student


"ashish128" wrote:

Hi,
I modified your code for actual values but on running it gives an
error,

"Run Time Error 1004"
Application defined or object defined error

Following is modified code
Sub gsnu()
Sheets("wax").Select
Range("C2:AN11").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("AK2"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

The Range is found selected when i stop the debugger.

Also can u tell me what is "xlSortNormal" and "matchcase" for and
difference between Order1 and orientation

Gary''s Student wrote:
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).





  #6  
Old August 17th, 2006, 05:52 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 7,584
Default macro code to sort a range

You are very welcome
--
Gary''s Student


"ashish128" wrote:

Hi, Thanks
You gave me the Idea. I self imitated the macro recording and found
that instead of "Range("AK2")" I must write "Range("AK3")" to make it
work. I dont know why i had to choose a value cell instead of a header
cell to make it work but as for now it works and all the thanks go to
you. Thanks again

Gary''s Student wrote:
I can't get your error message to appear. The code I posted is a direct copy
of the code generated by the Macro Recorder.
--
Gary's Student


"ashish128" wrote:

Hi,
I modified your code for actual values but on running it gives an
error,

"Run Time Error 1004"
Application defined or object defined error

Following is modified code
Sub gsnu()
Sheets("wax").Select
Range("C2:AN11").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("AK2"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

The Range is found selected when i stop the debugger.

Also can u tell me what is "xlSortNormal" and "matchcase" for and
difference between Order1 and orientation

Gary''s Student wrote:
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).






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.