Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() 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?!?!? |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Tab key problems | Excel Discussion (Misc queries) | |||
Tab key problems | Excel Discussion (Misc queries) | |||
problems with? I don't know | Excel Discussion (Misc queries) | |||
tab problems | New Users to Excel | |||
VBA problems | Excel Discussion (Misc queries) |