PC Review


Reply
Thread Tools Rate Thread

Copy active sheet tab

 
 
JDaywalt
Guest
Posts: n/a
 
      25th Jun 2008
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?

 
Reply With Quote
 
 
 
 
JDaywalt
Guest
Posts: n/a
 
      25th Jun 2008
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 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?
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy sheet and make new sheet active belvy123 Microsoft Excel Misc 5 24th Apr 2008 03:33 PM
Active Cell Copy And Paste Sheet to Sheet =?Utf-8?B?QS5SLkogQWxsYW4gSmVmZmVyeXM=?= Microsoft Excel New Users 4 4th May 2006 02:04 AM
How do i copy a active sheet to a new sheet with code and everything Karill Microsoft Excel Programming 2 11th Apr 2006 06:22 PM
Copy my active sheet to a new sheet and open with an input form Brad Withrow Microsoft Excel Programming 0 6th Apr 2006 03:56 AM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Microsoft Excel Programming 3 23rd Jan 2006 09:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:06 AM.