PC Review


Reply
Thread Tools Rate Thread

Code runs for a while, then stops working

 
 
Andrew
Guest
Posts: n/a
 
      18th Oct 2007
Hello,
Here's a code I am using to sort data each time the workbook opens.
This code runs fine for a while, and then, without changing the code,
stops working. When it stops, the error I get is: Run time error
1004. Application defined or object defined error. This seems like a
very simple code to write, and it does work sometimes. Can some
explain why it intermittently fails? If not, can you recommend a code
which will do the same task without fail?

thanks.
Andrew


Private Sub workbook_open()
Worksheets("data").Range(Cells(2, 1), Cells(50000, 7)).Sort
Key1:=Worksheets("data").Range("D2")
end Sub

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      18th Oct 2007
Those unqualified ranges (cells(2,1), cells(5000,7)) refer to the active
sheet--and that may not always be Data.

Private Sub workbook_open()
with Worksheets("data")
.Range(.Cells(2, 1), .Cells(50000, 7)).Sort _
Key1:=.Range("D2")
end with
end Sub


Andrew wrote:
>
> Hello,
> Here's a code I am using to sort data each time the workbook opens.
> This code runs fine for a while, and then, without changing the code,
> stops working. When it stops, the error I get is: Run time error
> 1004. Application defined or object defined error. This seems like a
> very simple code to write, and it does work sometimes. Can some
> explain why it intermittently fails? If not, can you recommend a code
> which will do the same task without fail?
>
> thanks.
> Andrew
>
> Private Sub workbook_open()
> Worksheets("data").Range(Cells(2, 1), Cells(50000, 7)).Sort
> Key1:=Worksheets("data").Range("D2")
> end Sub


--

Dave Peterson
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      18th Oct 2007
Private Sub workbook_open()
With Worksheets("data")
.Range(.Cells(2, 1), .Cells(50000, 7)).Sort
Key1:=.Range("D2")
End With
end Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Andrew" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> Here's a code I am using to sort data each time the workbook opens.
> This code runs fine for a while, and then, without changing the code,
> stops working. When it stops, the error I get is: Run time error
> 1004. Application defined or object defined error. This seems like a
> very simple code to write, and it does work sometimes. Can some
> explain why it intermittently fails? If not, can you recommend a code
> which will do the same task without fail?
>
> thanks.
> Andrew
>
>
> Private Sub workbook_open()
> Worksheets("data").Range(Cells(2, 1), Cells(50000, 7)).Sort
> Key1:=Worksheets("data").Range("D2")
> end Sub
>



 
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form code stops working davea Microsoft Access Forms 1 21st Oct 2010 04:45 AM
RE: code stops working after X rows. FSt1 Microsoft Excel Programming 4 25th Nov 2008 05:26 PM
VB Code stops working =?Utf-8?B?TWljaGVsbGUgSw==?= Microsoft Excel Programming 17 17th Aug 2007 05:58 PM
Create button code stops working Stuart Microsoft Excel Programming 5 1st May 2005 09:18 PM
dim statement stops code from working at all! Perry Microsoft Access VBA Modules 3 13th Apr 2004 10:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:22 AM.