|
-
Feb 8th, 2012, 01:29 PM
#1
Thread Starter
New Member
[RESOLVED][VBA] Help with macro to copy worksheet
Hi All,
I'm trying to create a macro that copies the current worksheet and places the copied ws before it. I've gotten as far as below, but that only copies the ws and places it in the second to last tab. Thanks in advance for any help.
Sub Copysheet()
Dim i As Integer
Dim p As Integer
On Error GoTo out
i = InputBox("How many copies would you like?", "Making Copies")
Application.ScreenUpdating = False
p = 0
Do
ActiveSheet.Copy Before:=Sheets(Sheets.Count)
p = p + 1
Loop Until p = i
Application.ScreenUpdating = True
Exit Sub
out:
MsgBox "Copy Cancelled"
Application.ScreenUpdating = True
End Sub
Last edited by newtovba; Feb 8th, 2012 at 03:45 PM.
Reason: Better heading
-
Feb 8th, 2012, 02:22 PM
#2
Junior Member
Re: [VBA] Help with macro to copy worksheet
Change
ActiveSheet.Copy Before:=Sheets(Sheets.Count)
to
ActiveSheet.Copy Before:=Sheets("NameofOriginalWorksheet")
-
Feb 8th, 2012, 03:02 PM
#3
Thread Starter
New Member
Re: [VBA] Help with macro to copy worksheet
I cant seem to get it to work. It goes to "copy cancelled"
Last edited by newtovba; Feb 8th, 2012 at 03:03 PM.
Reason: spelling
-
Feb 8th, 2012, 03:05 PM
#4
Junior Member
Re: [VBA] Help with macro to copy worksheet
Post the amended code for me.
-
Feb 8th, 2012, 03:09 PM
#5
Re: [VBA] Help with macro to copy worksheet
@LexGixxer
I take a guess, he did paste in exactly what you posted!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Feb 8th, 2012, 03:15 PM
#6
Thread Starter
New Member
Re: [VBA] Help with macro to copy worksheet
I should have said it does work, but by taking the name of worksheet, it will only allow me to copy that one specific worksheet over (I need to copy the current ws (which is then renamed and updated), and then copied again at a later date
Sub Copysheet()
Dim i As Integer
Dim p As Integer
On Error GoTo out
i = InputBox("How many copies would you like?", "Making Copies")
Application.ScreenUpdating = False
p = 0
Do
ActiveWorkbook.Sheets("February 12").Copy Before:=ActiveWorkbook.Sheets("February 12")
p = p + 1
Loop Until p = i
Application.ScreenUpdating = True
Exit Sub
out:
MsgBox "Copy Cancelled"
Application.ScreenUpdating = True
End Sub
-
Feb 8th, 2012, 03:18 PM
#7
Re: [VBA] Help with macro to copy worksheet
If need to work with the ActiveSheet just use ".ActiveSheet" instead of ".Sheets(xxxx)".
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Feb 8th, 2012, 03:23 PM
#8
Thread Starter
New Member
Re: [VBA] Help with macro to copy worksheet
Got it. Thanks.
A little new at this
-
Feb 8th, 2012, 03:23 PM
#9
Re: [VBA] Help with macro to copy worksheet
(I need to copy the current ws (which is then renamed and updated), and then copied again at a later date
how can the code know when these changes have been made and to now copy the worksheet?
unless you make these changes within the code, then copy again
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|