Sort a named range
let me reword your request to see if I understand it
You want the sort based on Column D for rows which have FIN in column C?
Just for the data in
A1:D5
I Assume A1:D1 are lables
there can be 1 to 4 rows with FIN in them
already adjacent
you want the range to be sorted in place.
Sub rangsrt()
nb = Application.WorksheetFunction.CountBlank(Range("C1 :C5"))
nf = Application.WorksheetFunction.CountIf(Range("C1:C5 "), "FIN")
sr = 6 - nb - nf
Range(Cells(sr, 1), Cells(sr + nf - 1, 4)).Select
Selection.Sort Key1:=Cells(sr, 4), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
"nc" wrote:
I have a named range, Data1 (A1 to D5)
A B C D
1 ID Name Code Dept
2 100 Sam HIS Histrory
3 201 Kid FIN Registry
4 301 Tom FIN Unknown
5 101 Grace Unknown
1. The range is sorted for FIN in column C to appear before a blank cell.
2.I would like to sort this named range using a macro from when the cell in
column C start to equal to FIN, by column D.
I would like the code only for point 2.
|