PP3321
Active Member
Dear Chandoo Community,
Thank you always for your help...
Today, I have 1 question for sorting in VBA.
When you determine key1,
why do we take the first row in the column?
Sorry I am out of office today and cannot test it myself, but
what if I take last value in that column?
Or what if I select multiple cells?
On the worksheet, I often select the entire rows before sorting.
So it makes more sense to do it like this...
*No headers
Sub Sort()
Range("A1:B5").Sort Key1:=Range("B1:B5")
End Sub
Or
Sub Sort()
Range("A1:B5").Sort Key1:=Range("B")
End Sub
Instead of...
Sub Sort()
Range("A1:B5").Sort Key1:=Range("B1")
End Sub
Is it to do with type of sorting?
We take the first value because algorithm takes the first value and start comparing from there?
I saw this but was not quite clear...
Developer Reference for Range.Sort
https://msdn.microsoft.com/en-us/library/office/ff840646.aspx
Thank you...
Thank you always for your help...
Today, I have 1 question for sorting in VBA.
When you determine key1,
why do we take the first row in the column?
Sorry I am out of office today and cannot test it myself, but
what if I take last value in that column?
Or what if I select multiple cells?
On the worksheet, I often select the entire rows before sorting.
So it makes more sense to do it like this...
*No headers
Sub Sort()
Range("A1:B5").Sort Key1:=Range("B1:B5")
End Sub
Or
Sub Sort()
Range("A1:B5").Sort Key1:=Range("B")
End Sub
Instead of...
Sub Sort()
Range("A1:B5").Sort Key1:=Range("B1")
End Sub
Is it to do with type of sorting?
We take the first value because algorithm takes the first value and start comparing from there?
I saw this but was not quite clear...
Developer Reference for Range.Sort
https://msdn.microsoft.com/en-us/library/office/ff840646.aspx
Thank you...