Sorting with code

  • Thread starter Thread starter JohnDK
  • Start date Start date
J

JohnDK

I want to sort data with a header row, can get it to work right, i'm
not to good at this. please help.

Private Sub cmdTIEImport_Click()

Workbooks.Open "C:\Documents and Settings\User\Desktop\11_01_2005.xls",
, False
AppActivate "Microsoft Excel"
ActiveSheet.Range("B:G,J:K,M:N,P:T,V:V,X:X,AC:AF,AH:AT,AV:BQ").Select
Selection.Delete Shift:=xlToLeft
ActiveSheet.Cells.Select
Cells.EntireColumn.AutoFit
ActiveSheet.Range("N1").Select
ActiveCell.FormulaR1C1 = "Dept Owner"
ActiveSheet.Range("O1").Select
ActiveCell.FormulaR1C1 = "Transaction Completed By"
ActiveSheet.Range("P1").Select
ActiveCell.FormulaR1C1 = "Control findings"
ActiveSheet.Range("Q1").Select
ActiveCell.FormulaR1C1 = "Results if errors not corrected"
ActiveSheet.Cells.Select
ActiveSheet.Cells.EntireColumn.AutoFit

I've tried the follwing for the sort, first one and then the other,
neither works.

1. ActiveSheet.Range("c1").Select
ActiveSheet.Range("c1").Sort Key1:=Columns("c1"), Header:=xlGuess

2. 'Worksheets("11_01_05").Range("C1").Sort _
'Key1:=Worksheets("11_01_05").Columns("C1"), Header:=xlGuess

Any suggestions appreciated
Thx
 
Range("C1:C15").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

There are other ways to sort but this is the one I use. Hopefilly it
helps you.

Good Luck.


I want to sort data with a header row, can get it to work right, i'm
not to good at this. please help.

Private Sub cmdTIEImport_Click()

Workbooks.Open "C:\Documents and Settings\User\Desktop\11_01_2005.xls",
, False
AppActivate "Microsoft Excel"
ActiveSheet.Range("B:G,J:K,M:N,P:T,V:V,X:X,AC:AF,AH:AT,AV:BQ").Select
Selection.Delete Shift:=xlToLeft
ActiveSheet.Cells.Select
Cells.EntireColumn.AutoFit
ActiveSheet.Range("N1").Select
ActiveCell.FormulaR1C1 = "Dept Owner"
ActiveSheet.Range("O1").Select
ActiveCell.FormulaR1C1 = "Transaction Completed By"
ActiveSheet.Range("P1").Select
ActiveCell.FormulaR1C1 = "Control findings"
ActiveSheet.Range("Q1").Select
ActiveCell.FormulaR1C1 = "Results if errors not corrected"
ActiveSheet.Cells.Select
ActiveSheet.Cells.EntireColumn.AutoFit

I've tried the follwing for the sort, first one and then the other,
neither works.

1. ActiveSheet.Range("c1").Select
ActiveSheet.Range("c1").Sort Key1:=Columns("c1"), Header:=xlGuess

2. 'Worksheets("11_01_05").Range("C1").Sort _
'Key1:=Worksheets("11_01_05").Columns("C1"), Header:=xlGuess

Any suggestions appreciated
Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top