PC Review Forums Newsgroups Microsoft Excel Microsoft Excel Crashes Application-defined or object-defined error

Reply

Application-defined or object-defined error

 
Thread Tools Rate Thread
Old 20-06-2007, 10:49 AM   #1
=?Utf-8?B?VkRV?=
Guest
 
Posts: n/a
Default Application-defined or object-defined error


Hello,

I made a script that sorts a range of cells and deletes rows that do not
comply with a condition. I get this error in Excel 2003 but I don't get it in
Excel 2007.
The debug highlights this line as location of the error:

ActiveSheet.Range(ActiveSheet.Range(first.Offset(stp, 0)),
ActiveSheet.Range(last.Offset(-1, 66))).Select

and the line is part of this context :

rownum = last.Row - first.Offset(stp, 0).Row
i = 1
Do While i <= rownum
Set rowx = ActiveSheet.Range(last.Offset(-i, 0), last.Offset(-i,
66))
If Application.WorksheetFunction.Max(rowx) = 0 Then
rowx.Delete shift:=xlShiftUp
rownum = rownum - 1
Else: i = i + 1
End If
Loop

ActiveSheet.Range(ActiveSheet.Range(first.Offset(stp, 0)),
ActiveSheet.Range(last.Offset(-1, 66))).Select
Selection.sort Key1:=Range(first.Offset(stp, 0), last.Offset(-1, 0)),
Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

This is a sorting script recorded with the macro recorder. first and last
are 2 range type variables which are set when the sub is called by another
sub, stp is an integer set also when the sub is called (it's value may be 2
or 3).
rownum and i are local integers and rowx is a local range.

I tried the 2007 sort method and the 2003 sort method and got errors but
just in Excel 2003. If you have any ideea how I could make this error
dissapear in Excel 2003, please tell me.

Thank you,


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off