Hi All,
I have a macro and I want to sort off of three columns:
[ul]
A
[/ul]
[ul]
R
[/ul]
[ul]
I
[/ul]
A - is just an alphabetical sort
R - I want to do a custom sort on
I - is just an Ascending value sort
This is how I want it to work - sort first off Column A, Then sort column R on a custom sort by "ignoring" Red, Yellow, and Green and only moving "Closed" to the bottom. Then "I" will just sort based on its value.
This is what I currently have:
The part that isn't working is Red, Yellow, Green, Closed - I want it to basically see Red Yellow Green as the same value and only move "Closed" to the bottom.
A data example would be:
A R I
1 Green -1
1 Yellow 2
2 Yellow 100
2 Closed 10
3 Red 50
3 Closed 250
It's basically a conditional grouping: If "Closed" then sort I ELSE sort I
- Matt
"If I must boast, I will boast of the things that show my weakness"
- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008
I have a macro and I want to sort off of three columns:
[ul]
A
[/ul]
[ul]
R
[/ul]
[ul]
I
[/ul]
A - is just an alphabetical sort
R - I want to do a custom sort on
I - is just an Ascending value sort
This is how I want it to work - sort first off Column A, Then sort column R on a custom sort by "ignoring" Red, Yellow, and Green and only moving "Closed" to the bottom. Then "I" will just sort based on its value.
This is what I currently have:
Code:
'Sort by I (Budget vs. Cost Plan) - putting Closed at the Bottom
Rows("1:" & LastRow).Select
Range("A135").Activate
ActiveWorkbook.Worksheets(X).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(X).Sort.SortFields.Add Key:=Range( _
"A2:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(X).Sort.SortFields.Add Key:=Range( _
"R2:R" & LastRow), SortOn:=xlSortOnValues, Order:=xlDescending, _
CustomOrder:="Red, Yellow, Green, Closed", _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(X).Sort.SortFields.Add Key:=Range( _
"I2:I" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(X).Sort
.SetRange Range("A1:AH" & LastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
The part that isn't working is Red, Yellow, Green, Closed - I want it to basically see Red Yellow Green as the same value and only move "Closed" to the bottom.
A data example would be:
A R I
1 Green -1
1 Yellow 2
2 Yellow 100
2 Closed 10
3 Red 50
3 Closed 250
It's basically a conditional grouping: If "Closed" then sort I ELSE sort I
- Matt
"If I must boast, I will boast of the things that show my weakness"
- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008