Kuldeep662
New Member
- Joined
- Apr 26, 2012
- Messages
- 2
Hi guys, i have small query regarding this and I havent found answer for this yet. Ofcourse I 'm new to this and not sure what do I do
I have following code which works
Range("F2 : F179").Select
Selection.Sort Key1:=Range("F2:F179"), Order1:=xlAscending _
, Order2:=xlYes, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Since I want to handle no. of rows dynamically for sorting i wrote following code...
Dim LastRow As Integer 'This is the LAST Non Empty Row
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Range("F2 : F & LastRow &").Select
Selection.Sort Key1:=Range("F2:F179"), Order1:=xlAscending _
, Order2:=xlYes, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Replacing 179 with LastRow variable doesnt work. When i print value of LastRow it prints correctly.
I get Method Range of Object _WorkSheet failed error. .
When i change above code to..
Dim LastRow As Integer 'This is the LAST Non Empty Row
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Worksheets("OverallITrac").Range("F2 : F & LastRow & ").Select
Selection.Sort Key1:=Range("F2:F & LastRow &"), Order1:=xlAscending _
, Order2:=xlYes, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Now I get Application defined or object defined error. PLease help. Thanks in advance.
Thanks,
Kuldeep
I have following code which works
Range("F2 : F179").Select
Selection.Sort Key1:=Range("F2:F179"), Order1:=xlAscending _
, Order2:=xlYes, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Since I want to handle no. of rows dynamically for sorting i wrote following code...
Dim LastRow As Integer 'This is the LAST Non Empty Row
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Range("F2 : F & LastRow &").Select
Selection.Sort Key1:=Range("F2:F179"), Order1:=xlAscending _
, Order2:=xlYes, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Replacing 179 with LastRow variable doesnt work. When i print value of LastRow it prints correctly.
I get Method Range of Object _WorkSheet failed error. .
When i change above code to..
Dim LastRow As Integer 'This is the LAST Non Empty Row
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Worksheets("OverallITrac").Range("F2 : F & LastRow & ").Select
Selection.Sort Key1:=Range("F2:F & LastRow &"), Order1:=xlAscending _
, Order2:=xlYes, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Now I get Application defined or object defined error. PLease help. Thanks in advance.
Thanks,
Kuldeep