Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default sorting error

I have a macro in an Access database that opens a new Excel workbook and
writes data to a sheet in the workbook. The macro then does "stuff" to the
data (sort, total, etc.)

I'm receiving an error message when the macro sorts. The message I get is:
"Method 'Range' of object_Global' Failed".

Following is the code used to sort the data:

..Range("A1").Select
..Range(.ActiveCell, .ActiveCell.Offset(0, 2)).Select
..Range(.Selection, .Selection.End(xlDown)).Select

**error occurs on the following line:

..Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _:=xlSortNormal

..Range("A1").Select

I don't get this error all of the time. I run the macro and it works. I
close Excel, run the macro again and get the error message. I click the
"end" button. If I re-run the macro, it works again. Is there anything I
can change or add to the code so I don't get this error?

Thanks for the help and suggestions..........



--
JT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sorting error

Your range references for the Key properties are not preceded by a period,
so they are unqualified and refer to the activesheet. If the activesheet
isn't the sheet being sorted, then you would get that error.

--
Regards,
Tom Ogilvy

"JT" wrote in message
...
I have a macro in an Access database that opens a new Excel workbook and
writes data to a sheet in the workbook. The macro then does "stuff" to the
data (sort, total, etc.)

I'm receiving an error message when the macro sorts. The message I get is:
"Method 'Range' of object_Global' Failed".

Following is the code used to sort the data:

.Range("A1").Select
.Range(.ActiveCell, .ActiveCell.Offset(0, 2)).Select
.Range(.Selection, .Selection.End(xlDown)).Select

**error occurs on the following line:

.Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2")

_
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _:=xlSortNormal

.Range("A1").Select

I don't get this error all of the time. I run the macro and it works. I
close Excel, run the macro again and get the error message. I click the
"end" button. If I re-run the macro, it works again. Is there anything I
can change or add to the code so I don't get this error?

Thanks for the help and suggestions..........



--
JT



  #3   Report Post  
Posted to microsoft.public.excel.programming
ste ste is offline
external usenet poster
 
Posts: 6
Default sorting error

Hi JT,

I'm not sure but try with the dot....

Selection.Sort Key1:=.Range("B2")...Key2:=.Range("C2") _

let me know,
regards,
ste

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
VBA Sorting Error Scott Halper Excel Worksheet Functions 1 March 19th 08 01:27 PM
Sorting error Daminc Excel Discussion (Misc queries) 4 April 11th 06 11:39 AM
sorting error ananga Excel Discussion (Misc queries) 2 June 30th 05 04:21 PM
sorting error abstsogds Excel Worksheet Functions 2 December 6th 04 07:19 PM
error in sorting hans[_3_] Excel Programming 1 April 22nd 04 11:09 AM


All times are GMT +1. The time now is 05:16 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"