Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Code runs for a while, then stops working

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code runs for a while, then stops working

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Code runs for a while, then stops working

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" wrote in message
oups.com...
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
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
IF just STOPS WORKING Gee Excel Worksheet Functions 21 August 6th 09 05:26 PM
VB Code stops working Michelle K Excel Programming 17 August 17th 07 05:58 PM
Can macro display a diff't screen while it runs until it stops? KT Excel Programming 2 January 5th 06 08:49 PM
After sharing workbook VB code stops working. Runtime Error 1004 Patrick LaFerriere Excel Programming 0 October 5th 05 04:01 PM
Create button code stops working Stuart[_21_] Excel Programming 5 May 1st 05 09:18 PM


All times are GMT +1. The time now is 06:22 PM.

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"