#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default VBA Problems

I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default VBA Problems

try this
Sheets("201").Copy after:=Sheets(Sheets.Count)

"Elise148" wrote:

I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default VBA Problems

That didn't work. It came up with an error saying "runtime error '1004': copy
method of worksheet class failed" Thanks for the suggestion though Mike.

"Mike" wrote:

try this
Sheets("201").Copy after:=Sheets(Sheets.Count)

"Elise148" wrote:

I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default VBA Problems

I'm sorry try this at the begging of code
On Error Resume Next


"Elise148" wrote:

That didn't work. It came up with an error saying "runtime error '1004': copy
method of worksheet class failed" Thanks for the suggestion though Mike.

"Mike" wrote:

try this
Sheets("201").Copy after:=Sheets(Sheets.Count)

"Elise148" wrote:

I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 42
Default VBA Problems

On Jul 2, 1:36 pm, Elise148
wrote:
I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?


What is the error message? I suspect since you are renaming
ActiveSheet you are actually renaming your source sheet by mistake.

Try:
Sheets("201").Copy After:=Sheets(sheets.count)
sheets(sheets.count).name = InputBox("Enter the number of the new
distributor.")

Peter



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default VBA Problems

Thanks Peter...That seemed to work...at least, for now it's working... :)

" wrote:

On Jul 2, 1:36 pm, Elise148
wrote:
I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?


What is the error message? I suspect since you are renaming
ActiveSheet you are actually renaming your source sheet by mistake.

Try:
Sheets("201").Copy After:=Sheets(sheets.count)
sheets(sheets.count).name = InputBox("Enter the number of the new
distributor.")

Peter


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default VBA Problems


Possibly...
http://support.microsoft.com/default...b;en-us;210684
"Copying Worksheet Programmatically Causes Run-Time Error 1004 in Excel"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"Elise148"
wrote in message
I'm trying to copy a worksheet and move and rename it to the end of the
workbook. This is the VBA code I have...

Sheets("201").Select
N = Sheets.Count
Sheets("201").Copy After:=Sheets(N)
ActiveSheet.Name = InputBox("Enter the number of the new distributor.")

It works for several times, but then an error comes up and it highlights the
third row. I don't understand! Any ideas?!?!?
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default VBA Problems

This works for me just fine every time: (well, i stopped at 20
sheets, but i think it'll be okay!)

Sub SheetsCount()
Dim i As Integer
i = Sheets.Count
Sheets("Sheet1").Copy After:=Sheets(i)
End Sub

....code is in a module, not a Sheet object.

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
Tab key problems jana Excel Discussion (Misc queries) 1 September 4th 06 12:33 AM
Tab key problems Marilyn Excel Discussion (Misc queries) 4 November 18th 05 05:32 PM
problems with? I don't know cliffhanger79 Excel Discussion (Misc queries) 1 November 4th 05 01:47 PM
tab problems JulieGirl New Users to Excel 2 April 26th 05 06:32 AM
VBA problems Andrew Clark Excel Discussion (Misc queries) 3 March 16th 05 09:33 PM


All times are GMT +1. The time now is 01:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"