Modify Macro to Include Inserted Rows
Try this. This will find the last cell with data in it in Col. A and then
sort row 2 thru LastRow.
Option Explicit
Sub SortRows()
Dim LastRow As Long
LastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
ActiveSheet.Rows("2:" & LastRow).Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
End Sub
--
Cheers,
Ryan
"Icefog" wrote:
I recorded a macro to sort rows:
Sub test2()
'
' test2 Macro
'
'
Rows("2:5").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
If I insert rows between 2 and 5 the macro does not change to include
the new rows. How do I change it so it is not a fixed selection?
Chris.....
|