Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Code inconsistent
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
LiAD  
View profile  
 More options Nov 9, 7:59 pm
Newsgroups: microsoft.public.excel.programming
From: LiAD <L...@discussions.microsoft.com>
Date: Mon, 9 Nov 2009 00:59:01 -0800
Local: Mon, Nov 9 2009 7:59 pm
Subject: Code inconsistent
Morning,

I was given a code to delete sheets 2-31 in a worksheet and then recreate
theam based on a modified sheet 1.  The delete part works fine but the
recreate code gets stuck on sheet 28.  It errors on the the following line
saying 1004 copy method of worksheet class failed.

Sheets("1").Copy After:=ActiveSheet

If i open the file i can add the sheet by hand (right click, copy/add sheet
etc).
If i then run the delete and then the recreate code it errors after sheet 10.

If open the original file, run the delete code, then the create code i get
28 sheets, then i rerun the delete code, then i rerun the create code it
creates no sheets and gives the same message straight away.

Any idea how i can stop this?

Code below
Thanks
LiAD

Sub CreateSheets()

Sheets("1").Select
Application.DisplayAlerts = False
On Error Resume Next
For x = 2 To 31
Sheets("1").Copy After:=ActiveSheet
Sheets("1 (2)").Name = CStr(x)
Next

End Sub


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Phillips  
View profile  
 More options Nov 9, 8:19 pm
Newsgroups: microsoft.public.excel.programming
From: "Bob Phillips" <Bob...@somewhere.com>
Date: Mon, 9 Nov 2009 09:19:35 -0000
Local: Mon, Nov 9 2009 8:19 pm
Subject: Re: Code inconsistent
It creates all 31 for me.

How many workbooks are open, how many sheets does it already have?

--
__________________________________
HTH

Bob

"LiAD" <L...@discussions.microsoft.com> wrote in message

news:80645942-297A-4073-90F8-97D690235566@microsoft.com...


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Skaria  
View profile  
 More options Nov 9, 8:26 pm
Newsgroups: microsoft.public.excel.programming
From: Jacob Skaria <JacobSka...@discussions.microsoft.com>
Date: Mon, 9 Nov 2009 01:26:01 -0800
Local: Mon, Nov 9 2009 8:26 pm
Subject: RE: Code inconsistent
Try this on activesheet

Sub CreateSheets()
Dim ws As Worksheet
Set ws = Sheets("1")

For x = 2 To 31
ws.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = CStr(x)
Next

End Sub

If this post helps click Yes
---------------
Jacob Skaria


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
joel  
View profile  
 More options Nov 9, 10:27 pm
Newsgroups: microsoft.public.excel.programming
From: joel <joel.41d...@thecodecage.com>
Date: Mon, 9 Nov 2009 11:27:01 +0000
Local: Mon, Nov 9 2009 10:27 pm
Subject: Re: Code inconsistent

What are your sheet names?  Do you have a sheet with the tab as "1", if
not you will get an error.

Usually Sheets(1) referes to the 1st tab in the workbook.  Sheets("1")
refers to a sheet name with the Tab being the number one.  Make sure
thtere arren't any spaces in the tab on the worksheet.  If the sheet
name is incorrect you would get an Run Error 9.

--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=152282

[url=&quot;http://www.thecodecage.com"]Microsoft Office Help[/url]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
GB  
View profile  
 More options Nov 10, 12:19 am
Newsgroups: microsoft.public.excel.programming
From: GB <G...@discussions.microsoft.com>
Date: Mon, 9 Nov 2009 05:19:01 -0800
Local: Tues, Nov 10 2009 12:19 am
Subject: RE: Code inconsistent
Jacob offers what probably works for your situation, seems reasonable upon
review.  As to why you can't figure out what was going on with your code, I
think it's because you have a few items that prevent displaying what you are
looking for. :)

The displayalerts = false I think disables your error messages, and if not
that then your on error resume next certainly takes you to the next line of
code until the system basically can't do anything else.

Hmmm, you may also want to try changing the copy line to read:
ws.Copy After:=Sheets(Cstr(x-1))

Not sure how the code responds if you have created say 31 sheets, then if
you created a sheet that was manually inserted before sheet 1.  If you then
ran your delete and create sheets in series it may add sheets 2-31 after the
newly created sheet and before sheet "1".

As for 31 sheets and recreating them from sheet 1, almost sounds like you
are working with something calendar related.  If so you can use other
variables to control your upper limit to the number of days in the month in
question.  Whatever the case, good luck.  Almost seems like you are there.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
LiAD  
View profile  
 More options Nov 10, 3:40 am
Newsgroups: microsoft.public.excel.programming
From: LiAD <L...@discussions.microsoft.com>
Date: Mon, 9 Nov 2009 08:40:01 -0800
Local: Tues, Nov 10 2009 3:40 am
Subject: RE: Code inconsistent
OK so heres the bad news

I can delete ok still but i cannot recreate all the sheets.

If I

- run the delete then the recreate i can create 19 sheets
- run the delete macro, save the file as a different name, run the create
macro i get 19 sheets.
- run the delete macro, save the file as a different name, close the file,
open the new file and run the create macro i get 27 sheets - almost there!!

The same thing happens above in using the line - ws.Copy
After:=Sheets(Cstr(x-1))  suggested by GB.

So there is something that is changing how the macro operates.  During the
time i run this i do nothing else other than open the file, run macros and
close as described above.  At the same time i have other applications open
(no other excel or word though).

Any other ideas?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
LiAD  
View profile  
 More options Nov 13, 3:08 am
Newsgroups: microsoft.public.excel.programming
From: LiAD <L...@discussions.microsoft.com>
Date: Thu, 12 Nov 2009 08:08:01 -0800
Local: Fri, Nov 13 2009 3:08 am
Subject: Re: Code inconsistent
Hi,

I have (or had) one workbook open.  It starts with either 33 sheets (which
then got deleted with the code and sheet 1 altered before running the create
code), or 3 sheets (file saved after the delete code had ran).


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
LiAD  
View profile  
 More options Nov 13, 3:10 am
Newsgroups: microsoft.public.excel.programming
From: LiAD <L...@discussions.microsoft.com>
Date: Thu, 12 Nov 2009 08:10:01 -0800
Local: Fri, Nov 13 2009 3:10 am
Subject: Re: Code inconsistent
The sheet names are correct without spaces etc ( if they were not right it
would not create any sheets surely, not 27 then stop?).

Is there something in memeory that could mean it bums out?  The reason I ask
is that it starts creating quite fast then slows down the more sheets it
creates.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google