ariesmethod
New Member
- Joined
- Apr 17, 2014
- Messages
- 9
I am trying to create a macro to catch all information for different time frames. For example, if there are 105 items, the macro below would only catch 100 of the items to sort. The selection for the macro does not have a specific range but the sort function does, which wouldn't make the macro work for all situations. Is there a way to make it based ONLY on selection?
'Sort all the information by description.
Sheets("ALL_DEDUCTIONS").Select
Cells.Find(What:="DED_CODE", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.Worksheets("ALL_DEDUCTIONS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ALL_DEDUCTIONS").Sort.SortFields.Add Key:=Range( _
"B2:B57"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ALL_DEDUCTIONS").Sort
.SetRange Range("A1:C100")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Thanks in advance!
'Sort all the information by description.
Sheets("ALL_DEDUCTIONS").Select
Cells.Find(What:="DED_CODE", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.Worksheets("ALL_DEDUCTIONS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ALL_DEDUCTIONS").Sort.SortFields.Add Key:=Range( _
"B2:B57"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("ALL_DEDUCTIONS").Sort
.SetRange Range("A1:C100")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Thanks in advance!