CurrentRegion in 2007 Sort

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Applying Variables to SORT 4
Sorting Question 5
Undo Macro Action 3
Sort Macro Compatibility 3
Modify Sort Routine to inlcude All Data 2
Clear Check Box 2
VBA 2 Codes 2
writing a sort macro 2

Back
Top