Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Need Help Troubleshooting

The code below is designed to copy the activesheet, clear the
contents, and place it at the front of the workbook. It works well,
but if I initiate the code a number of times without closing the
workbook I get an error:

Run-Time Error '1004'
Copy method of worksheet class failed.

Can any one figure out how to fix this problem, or explain why it
happens? Also if anyone has any suggestions for how to make my code
more efficient please let me know. Thank you.

John

Sub NewReport()
ActiveSheet.Copy Befo=Sheets(1)
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Range("F3,G6,G8,B17:K31,U17:AD31,AE17:AX31,_
B35:AB54,AE34:BG54,B58:BG72,B88:BG149,I162:AD203,_
AK162:BE185,AK188:BD203,H205,C206:BF211").Select
Selection.ClearContents
Range("BK17:BK31").Value = 7

If Sheets(1).Range("AZ3").Value < "" And
IsNumeric(Sheets(1).Range("AZ3").Value) = True Then
ActiveSheet.Range("AZ3").Value = Sheets(2).Range("AZ3").Value
+ 1
Else
ActiveSheet.Range("AZ3").Value = Application.Sheets.Count - 1
End If

If Sheets(2).Range("AX6").Value < "" Then
ActiveSheet.Range("AX6").Value = Sheets(2).Range("AX6").Value
+ 1
Else
ActiveSheet.Range("AX6").Value = Date
End If

Rows("77:290").Select
Selection.EntireRow.Hidden = True
ActiveSheet.Shapes("Text Box 9").Visible = False
ActiveSheet.Shapes("Button 5").Select
Selection.Characters.Text = "Add Gridpaper"
ActiveSheet.Shapes("Button 6").Select
Selection.Characters.Text = "Add Time Log"
ActiveSheet.Shapes("Button 8").Select
Selection.Characters.Text = "Add Narrative"
Range("BK34:BK42").Value = 0

Range("B17").Select
ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Need Help Troubleshooting

What version of Excel are you using ? How many is "a number of times" ?
What do the code names of the sheets look like ? Could they be something
like Sheet1111111... ?

You don't have to select things to work on them. So for example:

Range("F3,G6,G8,B17:K31,U17:AD31, ... ,C206:BF211").Select
Selection.ClearContents

would be:

Range("F3,G6,G8,B17:K31,U17:AD31, ... ,C206:BF211").ClearContents

Regards

Trevor


"mastermind" wrote in message
ups.com...
The code below is designed to copy the activesheet, clear the
contents, and place it at the front of the workbook. It works well,
but if I initiate the code a number of times without closing the
workbook I get an error:

Run-Time Error '1004'
Copy method of worksheet class failed.

Can any one figure out how to fix this problem, or explain why it
happens? Also if anyone has any suggestions for how to make my code
more efficient please let me know. Thank you.

John

Sub NewReport()
ActiveSheet.Copy Befo=Sheets(1)
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Range("F3,G6,G8,B17:K31,U17:AD31,AE17:AX31,_
B35:AB54,AE34:BG54,B58:BG72,B88:BG149,I162:AD203,_
AK162:BE185,AK188:BD203,H205,C206:BF211").Select
Selection.ClearContents
Range("BK17:BK31").Value = 7

If Sheets(1).Range("AZ3").Value < "" And
IsNumeric(Sheets(1).Range("AZ3").Value) = True Then
ActiveSheet.Range("AZ3").Value = Sheets(2).Range("AZ3").Value
+ 1
Else
ActiveSheet.Range("AZ3").Value = Application.Sheets.Count - 1
End If

If Sheets(2).Range("AX6").Value < "" Then
ActiveSheet.Range("AX6").Value = Sheets(2).Range("AX6").Value
+ 1
Else
ActiveSheet.Range("AX6").Value = Date
End If

Rows("77:290").Select
Selection.EntireRow.Hidden = True
ActiveSheet.Shapes("Text Box 9").Visible = False
ActiveSheet.Shapes("Button 5").Select
Selection.Characters.Text = "Add Gridpaper"
ActiveSheet.Shapes("Button 6").Select
Selection.Characters.Text = "Add Time Log"
ActiveSheet.Shapes("Button 8").Select
Selection.Characters.Text = "Add Narrative"
Range("BK34:BK42").Value = 0

Range("B17").Select
ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Need Help Troubleshooting

hi,
just guessing.
coping an entire sheet eats up the clipboard. and doing it several time is
may be crashing the macro. I've had this happen to me in the past when i had
the copy/paste commands in a loop. so i learned to avoid this by useing
variables ie assign a range(or cell) to a variable and then have another
range(or cell) as a variable equal the value of the first range thereby avoid
the cllipboard altogeather.
try this. after the copy add...
Application.cutcopymode = false.
in your code i don't set any where else you use the copy commands.
if that don't work well enough then rethink your copy and only copy what you
need instead of the entire sheet. or try it with variables.

Regards
FSt1

"mastermind" wrote:

The code below is designed to copy the activesheet, clear the
contents, and place it at the front of the workbook. It works well,
but if I initiate the code a number of times without closing the
workbook I get an error:

Run-Time Error '1004'
Copy method of worksheet class failed.

Can any one figure out how to fix this problem, or explain why it
happens? Also if anyone has any suggestions for how to make my code
more efficient please let me know. Thank you.

John

Sub NewReport()
ActiveSheet.Copy Befo=Sheets(1)
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Range("F3,G6,G8,B17:K31,U17:AD31,AE17:AX31,_
B35:AB54,AE34:BG54,B58:BG72,B88:BG149,I162:AD203,_
AK162:BE185,AK188:BD203,H205,C206:BF211").Select
Selection.ClearContents
Range("BK17:BK31").Value = 7

If Sheets(1).Range("AZ3").Value < "" And
IsNumeric(Sheets(1).Range("AZ3").Value) = True Then
ActiveSheet.Range("AZ3").Value = Sheets(2).Range("AZ3").Value
+ 1
Else
ActiveSheet.Range("AZ3").Value = Application.Sheets.Count - 1
End If

If Sheets(2).Range("AX6").Value < "" Then
ActiveSheet.Range("AX6").Value = Sheets(2).Range("AX6").Value
+ 1
Else
ActiveSheet.Range("AX6").Value = Date
End If

Rows("77:290").Select
Selection.EntireRow.Hidden = True
ActiveSheet.Shapes("Text Box 9").Visible = False
ActiveSheet.Shapes("Button 5").Select
Selection.Characters.Text = "Add Gridpaper"
ActiveSheet.Shapes("Button 6").Select
Selection.Characters.Text = "Add Time Log"
ActiveSheet.Shapes("Button 8").Select
Selection.Characters.Text = "Add Narrative"
Range("BK34:BK42").Value = 0

Range("B17").Select
ActiveSheet.Protect
Application.ScreenUpdating = True
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
Troubleshooting David Rogers Excel Discussion (Misc queries) 2 November 26th 08 12:02 PM
Function Troubleshooting Sarah Excel Worksheet Functions 1 June 7th 07 10:28 PM
Troubleshooting Spreadsheets valkyrie Excel Discussion (Misc queries) 1 August 1st 06 04:24 AM
troubleshooting Mr. Lucky69 Setting up and Configuration of Excel 0 April 29th 06 08:57 PM
DDE Troubleshooting Opterabot22 Excel Programming 2 May 13th 04 11:30 PM


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