ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting Problem (https://www.excelbanter.com/excel-programming/431142-sorting-problem.html)

Helmut

Sorting Problem
 
excel 2007

what's wrong with the following sort?

Sub Macro1()

Range("B3").Select
lastrow = Range("B" & Rows.Count).End(xlUp).Row
Set SortRange = Rows("3:" & lastrow)
SortRange.Sort , key1:=Range("C2"), _
order1:=xlAscending, _
key2:=Range("B2"), _
order2:=xlAscending, _
Header:=xlYes

End Sub

It stops at SortRange.Sort

ryguy7272

Sorting Problem
 

What about this:

FirstRow = 2
lastrow = Range("B" & Rows.Count).End(xlUp).Row
Set SortRange = Range("B" & FirstRow & ":C" & lastrow)
SortRange.Sort Key1:=Range("C1"), Order1:=xlAscending, Key2:=Range("B1"),
Order2:=xlAscending, Header:=xlGuess

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Helmut" wrote:

excel 2007

what's wrong with the following sort?

Sub Macro1()

Range("B3").Select
lastrow = Range("B" & Rows.Count).End(xlUp).Row
Set SortRange = Rows("3:" & lastrow)
SortRange.Sort , key1:=Range("C2"), _
order1:=xlAscending, _
key2:=Range("B2"), _
order2:=xlAscending, _
Header:=xlYes

End Sub

It stops at SortRange.Sort



All times are GMT +1. The time now is 01:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com