SortArea1

Sorts a range or area by 1 column given its cell address, with options to choose, order, sheet, workbook

CodeFunctionName
What is this?

Public

Tested

Original Work
Sub SortArea1(Sorted_Range, SortByCell, Optional Order_Asc1_Desc2 = 1, Optional SheetName = "This", optional WBName = "This")
' Sorted_Range is the actual area to be sorted, like A4:H200
' SoryByCell is the column to sort by, like B4
If WBName = "This" then WBName = Thisworkbook.Name
If SheetName = "This" then SheetName = Activesheet.name
OOrd = xlAscending
If Order_Asc1_Desc2 = 2 Then OOrd = xlDescending
Workbooks(WBName).Worksheets(SheetName).Sort.SortFields.Clear
Workbooks(WBName).Worksheets(SheetName).Sort.SortFields.Add Key:=Workbooks(WBName).Worksheets(SheetName).Range(SortByCell), SortOn:=xlSortOnValues, Order:=OOrd, DataOption:=xlSortNormal
With Workbooks(WBName).Worksheets(SheetName).Sort
.SetRange Workbooks(WBName).Worksheets(SheetName).Range(Sorted_Range)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

Sorted_Range, SortByCell, Optional Order_Asc1_Desc2, Optional SheetName, optional WBName

Sorted_Range is the actual area to be sorted, like A4:H200
SoryByCell is the column to sort by, like B4

Views 3,331

Downloads 1,339

CodeID
DB ID

ANmarAmdeen
633
Attachments
Revisions

v1.0

Wednesday
July
4
2018