Hello,
I was trying to record a macro to auto sort my data in custom order
1.Pending
2.Actioned
But I needed it to auto sort everytime I added data from userform to my worksheet.
I have 20 columns and the column I need my data to sort according to its values are based on Column 7(H)
I was trying to record a macro to auto sort my data in custom order
1.Pending
2.Actioned
But I needed it to auto sort everytime I added data from userform to my worksheet.
I have 20 columns and the column I need my data to sort according to its values are based on Column 7(H)
VBA Code:
Sub Sort()
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Data").Sort.SortFields.Add2 Key:=Range("G2:G73"), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="Pending", _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Data").Sort
.SetRange Range("A1:T73")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWindow.SmallScroll Down:=0
End Sub