#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Sorting issue

Here is an easy one, but I just can't get it right. I trying to sort data in
a file just opened. But when it get to the sort part I get an "informative"
400 error.

Sub GetDataFromFCDBFile()
Dim wb As Workbook
Set wb = Workbooks.Open("H:\myfolder\MyFile.xls", True, False, , , , True)
'wb.Worksheets("ProdBatch").Cells.copy
Destination:=ThisWorkbook.Worksheets("Bulk Batch Lookup").Range("A1")

With wb.Worksheets("ProdBatch").Cells
.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
End With
End Sub

Anyone?
The Doctor
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Sorting issue

Doctor,

.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _

Should be

.Sort Key1:=.Range("A2"), Order1:=xlAscending, Key2:=.Range("B2") _


Note the dot before the Range - that makes the key range part of the sorted range, otherwise it is a
range on the default worksheet.

HTH,
Bernie
MS Excel MVP


"Dr. Schwartz" wrote in message
...
Here is an easy one, but I just can't get it right. I trying to sort data in
a file just opened. But when it get to the sort part I get an "informative"
400 error.

Sub GetDataFromFCDBFile()
Dim wb As Workbook
Set wb = Workbooks.Open("H:\myfolder\MyFile.xls", True, False, , , , True)
'wb.Worksheets("ProdBatch").Cells.copy
Destination:=ThisWorkbook.Worksheets("Bulk Batch Lookup").Range("A1")

With wb.Worksheets("ProdBatch").Cells
.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
End With
End Sub

Anyone?
The Doctor



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Sorting issue

Not so simple after all to a VBA novice I guess - thanks a lot Bernie!

"Bernie Deitrick" wrote:

Doctor,

.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _

Should be

.Sort Key1:=.Range("A2"), Order1:=xlAscending, Key2:=.Range("B2") _


Note the dot before the Range - that makes the key range part of the sorted range, otherwise it is a
range on the default worksheet.

HTH,
Bernie
MS Excel MVP


"Dr. Schwartz" wrote in message
...
Here is an easy one, but I just can't get it right. I trying to sort data in
a file just opened. But when it get to the sort part I get an "informative"
400 error.

Sub GetDataFromFCDBFile()
Dim wb As Workbook
Set wb = Workbooks.Open("H:\myfolder\MyFile.xls", True, False, , , , True)
'wb.Worksheets("ProdBatch").Cells.copy
Destination:=ThisWorkbook.Worksheets("Bulk Batch Lookup").Range("A1")

With wb.Worksheets("ProdBatch").Cells
.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
End With
End Sub

Anyone?
The Doctor




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting issue Linda Broyles Excel Worksheet Functions 2 December 7th 07 10:36 PM
Sorting Issue - Any help? AwfulTruth Excel Worksheet Functions 1 March 9th 07 07:17 PM
Sorting Issue. Please help V-ger Excel Discussion (Misc queries) 17 November 15th 05 12:27 AM
Sorting Issue Sean DeBruler Excel Discussion (Misc queries) 4 November 10th 05 07:00 PM
sorting issue steve Excel Discussion (Misc queries) 4 June 22nd 05 06:28 PM


All times are GMT +1. The time now is 06:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"