eng_khalid
06-27-2009, 11:50 AM
is there a way to sort a variable sized range?
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=ActiveCell. _
Offset(-1, 0).Range("A1:A41"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange ActiveCell.Offset(-2, -17).Range("A1:AI42")
.Header = xlYes
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
that's the code...is there a way to replace the " Range("A1:A41") " with a code that is flexible with the size of range?
I tried Range.CurrentRegion but it didn't work:(
any ideas
thnx in advance
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=ActiveCell. _
Offset(-1, 0).Range("A1:A41"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange ActiveCell.Offset(-2, -17).Range("A1:AI42")
.Header = xlYes
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
that's the code...is there a way to replace the " Range("A1:A41") " with a code that is flexible with the size of range?
I tried Range.CurrentRegion but it didn't work:(
any ideas
thnx in advance