Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default CurrentRegion in 2007 Sort

I used to add currentregion to a sort macro in 2003 so that as the list
increased, the macro would automatically include the new items. I can't
figure out how to do that in 2007. Below is a sample recorded macro with a
specified range. How do I make it "grow" automatically as the list grows?
Thanks.

Sub Macro2()
ActiveWorkbook.Worksheets("Quarter 1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Quarter 1").Sort.SortFields.Add
Key:=Range("E4"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Quarter 1").Sort
.SetRange Range("A4:G78")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default CurrentRegion in 2007 Sort

Untested...

I'd qualify all the ranges:

Sub Macro2()
with ActiveWorkbook.Worksheets("Quarter 1")
.Sort.SortFields.Clear
.Sort.SortFields.Add _
Key:=.Range("E4"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
with .sort
.SetRange .Range("A4").currentregion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
end with
End Sub

But there's no reason you can't use the old xl2003 syntax:

with ActiveWorkbook.Worksheets("Quarter 1")
with .range("a4").currentregion
.sort key1:=.columns(5), _
order1:=xlAscending, _
header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
end with
end with

Andy wrote:

I used to add currentregion to a sort macro in 2003 so that as the list
increased, the macro would automatically include the new items. I can't
figure out how to do that in 2007. Below is a sample recorded macro with a
specified range. How do I make it "grow" automatically as the list grows?
Thanks.

Sub Macro2()
ActiveWorkbook.Worksheets("Quarter 1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Quarter 1").Sort.SortFields.Add
Key:=Range("E4"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Quarter 1").Sort
.SetRange Range("A4:G78")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub


--

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
Why can't I sort a 2003 file in 2007? 2007 freezes. lw2007 Excel Discussion (Misc queries) 0 April 27th 09 07:41 PM
sort function for dates does not sort properly in Office 2007 Exc. Rosalie Excel Worksheet Functions 1 November 22nd 07 10:25 PM
currentregion flow23 Excel Discussion (Misc queries) 13 November 23rd 05 05:02 PM
CurrentRegion less one Row GregR Excel Programming 8 November 7th 05 05:16 PM
CurrentRegion Steph[_3_] Excel Programming 2 August 10th 04 07:00 PM


All times are GMT +1. The time now is 06:29 AM.

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"