Medicine1
asked on
Filtering
This code is working great but I need to add to it - I need three columns sorted
The First sort would be the code below
The Second sort would be by column D2 ascending which has numbers and text. I need the number values sorted first in this column the text will say "None" or could be null.
The Third sort would be by Column O2 ascending which is text.
Private Sub sortmainlist()
Dim rng As Range
Dim listnum As Long
On Error Resume Next
Application.AddCustomList ListArray:=Array("Top", "Middle", "Bottom")
listnum = Application.GetCustomListN um(Array(" Top", "Middle", "Bottom"))
Thank you in advance.
With Sheets("Sheet1")
.Activate
Set rng = Range(.Cells(2, "A"), .Cells(.Rows.Count, 1).End(xlUp).Offset(0, 5))
End With
'Note: listnum+1
rng.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=listnum + 1, _
MatchCase:=False, Orientation:=xlTopToBottom , DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
Application.DeleteCustomLi st listnum
End Sub
The First sort would be the code below
The Second sort would be by column D2 ascending which has numbers and text. I need the number values sorted first in this column the text will say "None" or could be null.
The Third sort would be by Column O2 ascending which is text.
Private Sub sortmainlist()
Dim rng As Range
Dim listnum As Long
On Error Resume Next
Application.AddCustomList ListArray:=Array("Top", "Middle", "Bottom")
listnum = Application.GetCustomListN
Thank you in advance.
With Sheets("Sheet1")
.Activate
Set rng = Range(.Cells(2, "A"), .Cells(.Rows.Count, 1).End(xlUp).Offset(0, 5))
End With
'Note: listnum+1
rng.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=listnum + 1, _
MatchCase:=False, Orientation:=xlTopToBottom
DataOption2:=xlSortNormal
Application.DeleteCustomLi
End Sub
Could you provide data to test?
ASKER
I have included data on sheet2 and code in attached. Let me know if you need anything else.
1st sort will be column F
2nd by column B
3rd by column C
Thank you!!
Book3.xlsx
1st sort will be column F
2nd by column B
3rd by column C
Thank you!!
Book3.xlsx
Did you mean something like the attached?
Sub Macro1()
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SortFields.Clear
.SetRange Range("A1:F13")
.Header = xlYes
.SortFields.Add Key:=Range("F2:F5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("B2:B5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("C2:C5000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Book3.xls
Medicine1,
In this question you started out by saying that you wanted it sorted by:
1st column F
2nd column D
3rd column O
now your most recent requirement is:
1st sort will be column F
2nd by column B
3rd by column C
I am going to take it that in the original file you are now wanting it as your most recent requirement as there is no data in column O.
Patrick
In this question you started out by saying that you wanted it sorted by:
1st column F
2nd column D
3rd column O
now your most recent requirement is:
1st sort will be column F
2nd by column B
3rd by column C
I am going to take it that in the original file you are now wanting it as your most recent requirement as there is no data in column O.
Patrick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am reattaching the file for the code above. The Names are not sorting. I added some names to see.
I told you wrong
The columnas are
F
B
D
sort order
but replacd C with D and did not work...
reorg-09.xls
I told you wrong
The columnas are
F
B
D
sort order
but replacd C with D and did not work...
reorg-09.xls
ASKER
Never mind Patrick... looks like yours is working. I have to figure why not working in my sheet....
Thank you....
Thank you....
ASKER
Works Great
Medicine1 - Thanks for the grade - Patrick