Copy active sheet tab

J

JDaywalt

I have a workbook containing several sheet tabs. I want to include code that
allows the user to replicate or 'copy' any of these sheet tabs and place the
new sheet directly to the right of the sheet they 'copied' from. For
example, let's say the sequence of existing sheet tabs is "Jones", "Smith",
and "Taylor". If a user is on "Smith" when they perform the copy, I want the
"Smith (2)" sheet to fall directly to the right of the current "Smith" sheet.
I have tried recording a macro to copy the sheet & was planning to
substitute the actual sheet name (Smith) with the more generic 'ActiveSheet'
reference, but I don't know how to adjust for the hard-coded Sheets(5) value
that appears in the last line of code-----Here is what my recorded code looks
like right now:
Sheets("Smith").Select
Sheets("Smith").Copy Before:=Sheets(5)
How can I adjust so it performs the generic "copy directly to the right"
function based on whichever active sheet I'm on at the time code is executed?
 
J

JDaywalt

Just figured it out on my own -- used the following code & it worked
perfectly!!

ActiveSheet.Copy After:=ActiveSheet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top