Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting in Excell - VBA code

Status
Not open for further replies.

Evening

Technical User
Jan 19, 2005
45
0
0
CA
Can someone help me to solve my little problem.
I have 2 sheets, RPN & FMA. I'm making a VBA codes in sheet RPN.

I am in RPN sheet and want to go to sheet FMA. I want to sort it according some criteria, then copy first 10 rows, come back to sheet RPN again, and paste the copied fields.
The problem is when i start sorting the fields in FMA, it gives me an error. Why?
here is my program:

Sheets("RPN").Select
.
.
.
Sheets("FMA").Select
cursht = ActiveSheet.Name
LastRow = ActiveSheet.Range("B65536").End(xlUp).Row
ActiveSheet.Rows("11:" & LastRow).Select

Selection.Sort Key1:=Range("G11"), Order1:=xlAscending, Key2:=Range("B11" _
), Order2:=xlAscending, Key3:=Range("C11"), Order3:=xlAscending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal

ActiveSheet.Range("B11:C20").Select
Selection.Copy
Sheets("RPN").Select
Range("C10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
it gives me an error
Which error ?
Which line is highlighted when in debug mode ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'm sorry i forgot to put the line of error
. When it get's to sorting, so line :

Selection.Sort Key1:=Range("G11"), Order1:=xlAscending, Key2:=Range("B11" _ ), Order2:=xlAscending, Key3:=Range("C11"), Order3:=xlAscending, Header _ :=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom _ , DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal


Is there different instruction for sorting when you run the code from sheet RPN and sort in FMA?
 



Is there different instruction for sorting when you run the code from sheet RPN and sort in FMA?
ABSOLUTELY!!!
Code:
With Sheets("FMA")
  .[b110].Sort _
    Key1:=[red][b].[/b][/red]Range("G11"), Order1:=xlAscending, _
    Key2:=[red][b].[/b][/red]Range("B11"), Order2:=xlAscending, _
    Key3:=[red][b].[/b][/red]Range("C11"), Order3:=xlAscending, _
    Header:=xlGuess, _
    OrderCustom:=1, _
    MatchCase:=False, _
    Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, _
    DataOption2:=xlSortNormal, _
    DataOption3:=xlSortNormal
End With


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks Skip, it's working. I love this web site, I can always find someone to help me

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top