Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default sorting language

I have a named range ("SortRange") in my '07 wkbk. I need a macro which will
take that range and use the 20th column to sort the whole thing in place,
ascending order. Any help on some code for this?

Below is what my recorder picked up on a few tries:

Sub SumSort()
'
' SumSort Macro
'

'
Application.Goto Reference:="SummarySortRange"
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Add
Key:= _
ActiveCell.Offset(0, 20).Range("A1:A55"), SortOn:=xlSortOnValues,
Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Overall YoY Summary").Sort
.SetRange ActiveCell.Range("A1:U55")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Sub Sorter()
'
' Sorter Macro
'
Dim SortRange As Range

'
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Add
Key:= _
Range("a7").Offset(0, 20), SortOn:=xlSortOnValues,
Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Overall YoY Summary").Sort
.SetRange Range("A7:U61")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub


what I'm struggling with is the fact that the range size is not set, and may
change. So I don't want the hard references to a sized range, but rather
something that will dynamically set the height. For the definition of
SortRange, for example, I used

=OFFSET('Overall YoY Summary'!$A$7,0,0,COUNTA('Overall YoY
Summary'!$A:$A)-3,COUNTA('Overall YoY Summary'!$7:$7)*2-1)

and so that takes care of the case that the range grows in height or width.
But in code, I don't know how to make this dynamic range.

Thanks for any assistance.
--
Boris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default sorting language

The 20th column of the SortRange range?

with worksheets("somesheetnamehere").range("sortrange")
.cells.sort key1:=.columns(20), Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
end with

Since it's your data, don't you know whether it has headers or not? Why let
excel guess?

(This worked in xl2003.)

BorisS wrote:

I have a named range ("SortRange") in my '07 wkbk. I need a macro which will
take that range and use the 20th column to sort the whole thing in place,
ascending order. Any help on some code for this?

Below is what my recorder picked up on a few tries:

Sub SumSort()
'
' SumSort Macro
'

'
Application.Goto Reference:="SummarySortRange"
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Add
Key:= _
ActiveCell.Offset(0, 20).Range("A1:A55"), SortOn:=xlSortOnValues,
Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Overall YoY Summary").Sort
.SetRange ActiveCell.Range("A1:U55")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Sub Sorter()
'
' Sorter Macro
'
Dim SortRange As Range

'
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Overall YoY Summary").Sort.SortFields.Add
Key:= _
Range("a7").Offset(0, 20), SortOn:=xlSortOnValues,
Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Overall YoY Summary").Sort
.SetRange Range("A7:U61")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

what I'm struggling with is the fact that the range size is not set, and may
change. So I don't want the hard references to a sized range, but rather
something that will dynamically set the height. For the definition of
SortRange, for example, I used

=OFFSET('Overall YoY Summary'!$A$7,0,0,COUNTA('Overall YoY
Summary'!$A:$A)-3,COUNTA('Overall YoY Summary'!$7:$7)*2-1)

and so that takes care of the case that the range grows in height or width.
But in code, I don't know how to make this dynamic range.

Thanks for any assistance.
--
Boris


--

Dave Peterson
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
How to change German language data into Eglish Language in a colum Execel work sheet language problems Excel Discussion (Misc queries) 1 October 29th 07 09:59 PM
Right to Left sorting without changing language settings Natemoney2 Excel Discussion (Misc queries) 2 July 18th 07 06:24 PM
language support in excel sheet using a third party language tool seema Excel Worksheet Functions 0 March 13th 06 06:06 AM
OS language and Office language conflicts teejay Excel Worksheet Functions 1 February 10th 06 05:31 PM
How to change the excel format from language to language? zee Excel Discussion (Misc queries) 2 January 30th 05 06:51 PM


All times are GMT +1. The time now is 06:29 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"