Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Copy active sheet tab
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 Befo=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? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Copy active sheet tab
Just figured it out on my own -- used the following code & it worked
perfectly!! ActiveSheet.Copy After:=ActiveSheet "JDaywalt" wrote: 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 Befo=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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Copy sheet and make new sheet active | Excel Discussion (Misc queries) | |||
Copy active sheet to new - do no copy buttons | Excel Programming | |||
Active Cell Copy And Paste Sheet to Sheet | New Users to Excel | |||
Copy my active sheet to a new sheet and open with an input form | Excel Programming | |||
Copy from active sheet and paste into new sheet using info from cell in active | Excel Programming |