#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Sort Macro

Hi All

Below is the code for a sort Macro works OK no problem - the question is
that on the sheet there are 20 blocks of 4 line ranges all in the same
columns. How would I incorporate them in this little macro. Ranges are as
follows C2:D5, C6:D9, C10:D13, C14:D17 as so on down to ranges C54:D57

Sub Macro8()
Sheets("Lindop").Select
Range("C2:D5").Select
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Add
Key:=Range("D22:D25") _
, SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lindop").Sort
.SetRange Range("C2:D5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

--
Many thanks

hazel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Sort Macro

hi Hazel,
I copied your code and pasted into a standard module and my compiler freaked
out.
turned all the code red. so i rewrote it.
try this.
Sub Sort4LinesInColumn()
Sheets("Sheet2").Select
Range("C2").Select

Do While Not IsEmpty(ActiveCell)
Range(Selection, Selection.Offset(3, 1)).Select

Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveCell.Select
ActiveCell.Offset(4, 0).Activate
Loop

End Sub
I am using xp and this code sorted 4 groups of 4 lines in the same columns
...number and letters.
give it a try and post back if you have problems. do it in step mode.

Regards
FSt1

"Hazel" wrote:

Hi All

Below is the code for a sort Macro works OK no problem - the question is
that on the sheet there are 20 blocks of 4 line ranges all in the same
columns. How would I incorporate them in this little macro. Ranges are as
follows C2:D5, C6:D9, C10:D13, C14:D17 as so on down to ranges C54:D57

Sub Macro8()
Sheets("Lindop").Select
Range("C2:D5").Select
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Add
Key:=Range("D22:D25") _
, SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lindop").Sort
.SetRange Range("C2:D5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

--
Many thanks

hazel

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Sort Macro

Hi

Going to have a go now -- probably should have indicated I recorded the
macro in Excel 2007.

Will let you know how I get on.
--
Many thanks

hazel


"FSt1" wrote:

hi Hazel,
I copied your code and pasted into a standard module and my compiler freaked
out.
turned all the code red. so i rewrote it.
try this.
Sub Sort4LinesInColumn()
Sheets("Sheet2").Select
Range("C2").Select

Do While Not IsEmpty(ActiveCell)
Range(Selection, Selection.Offset(3, 1)).Select

Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveCell.Select
ActiveCell.Offset(4, 0).Activate
Loop

End Sub
I am using xp and this code sorted 4 groups of 4 lines in the same columns
..number and letters.
give it a try and post back if you have problems. do it in step mode.

Regards
FSt1

"Hazel" wrote:

Hi All

Below is the code for a sort Macro works OK no problem - the question is
that on the sheet there are 20 blocks of 4 line ranges all in the same
columns. How would I incorporate them in this little macro. Ranges are as
follows C2:D5, C6:D9, C10:D13, C14:D17 as so on down to ranges C54:D57

Sub Macro8()
Sheets("Lindop").Select
Range("C2:D5").Select
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Add
Key:=Range("D22:D25") _
, SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lindop").Sort
.SetRange Range("C2:D5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

--
Many thanks

hazel

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Sort Macro

Hi

I have inserted and run your code - however it will not sort the criteria of
column D followed by column C -- again I have looked at the macro above and
there is an error in the typing that is probably why the code turned Red when
you tried have highlighted the error below. Perhaps another go at it please.

Sub Macro8()
Sheets("Lindop").Select
Range("C2:D5").Select
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Add
'Key:=Range("D2:D5") _ <<< should be this not the line below
Key:=Range("D22:D25") _
, SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lindop").Sort
..SetRange Range("C2:D5")
..Header = xlGuess
..MatchCase = False
..Orientation = xlTopToBottom
..SortMethod = xlPinYin
..Apply
End With
End Sub

--
Many thanks

hazel


"FSt1" wrote:

hi Hazel,
I copied your code and pasted into a standard module and my compiler freaked
out.
turned all the code red. so i rewrote it.
try this.
Sub Sort4LinesInColumn()
Sheets("Sheet2").Select
Range("C2").Select

Do While Not IsEmpty(ActiveCell)
Range(Selection, Selection.Offset(3, 1)).Select

Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveCell.Select
ActiveCell.Offset(4, 0).Activate
Loop

End Sub
I am using xp and this code sorted 4 groups of 4 lines in the same columns
..number and letters.
give it a try and post back if you have problems. do it in step mode.

Regards
FSt1

"Hazel" wrote:

Hi All

Below is the code for a sort Macro works OK no problem - the question is
that on the sheet there are 20 blocks of 4 line ranges all in the same
columns. How would I incorporate them in this little macro. Ranges are as
follows C2:D5, C6:D9, C10:D13, C14:D17 as so on down to ranges C54:D57

Sub Macro8()
Sheets("Lindop").Select
Range("C2:D5").Select
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Lindop").Sort.SortField s.Add
Key:=Range("D22:D25") _
, SortOn:=xlSortOnValues, Order:=xlDescending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lindop").Sort
.SetRange Range("C2:D5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

--
Many thanks

hazel

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Using Macro to sort without clicking on macro button dd Excel Discussion (Misc queries) 3 May 3rd 07 06:00 PM
Sort Macro kronik Excel Discussion (Misc queries) 0 March 13th 06 03:58 PM
Sort Macro kronik Excel Programming 0 March 13th 06 04:55 AM
Sort Macro Sprinks Excel Discussion (Misc queries) 1 April 19th 05 04:58 PM


All times are GMT +1. The time now is 12:22 PM.

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

About Us

"It's about Microsoft Excel"