+ Reply to Thread
Results 1 to 8 of 8

VBA to copy multiple worksheets and then rename them

  1. #1
    Registered User
    Join Date
    12-16-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2007
    Posts
    34

    VBA to copy multiple worksheets and then rename them

    Hi
    I'm new to the forum and VBA.
    I need a command button on a worksheet called "Costings Main Menu" to copy 3 other worksheets and then rename them.
    The 3 worksheets to be copied are called "Yearly Lease Order", "Yearly Quote Form", and "Yearly Invoice Form".
    I would like the new sheets to be named the same as the sheets they were copied from with the addition of the contents of a cell (C4) in the "Costings Main Menu" worksheet.
    So if I typed SIMAT in cell (C4) the new sheets would be named as follows:
    "SIMAT Yearly Lease Order", "SIMAT Yearly Quote Form", and "SIMAT Yearly Invoice Form"

    This is all contained within the same workbook
    Any help with this will be very much appreciated

    Thanks

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA to copy multiple worksheets and then rename them

    Welcome to the forum!

    Put this code in a Module.

    Please Login or Register  to view this content.
    Call the sub Copy3Sheets from an activex commandbutton's Click event:
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to copy multiple worksheets and then rename them

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-16-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: VBA to copy multiple worksheets and then rename them

    Thank you so much for the quick reply. Your code worked perfectly!!!!

    rikk

  5. #5
    Registered User
    Join Date
    12-16-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: VBA to copy multiple worksheets and then rename them

    Hello
    The code I'm using below which I got from a post by Kenneth Hobson works great for 3 sheets.
    How can I make the code below work to just copy and rename 1 sheet? Ive tried tinkering without sucess.
    Also is it possible to do the same as above regardless of whether the sheets that its copying from are hidden or visible
    Id be grateful for any help at all


    Hello
    Sub Copy3Sheets()
    Dim ws(1 To 3) As Worksheet, v As Variant, s As String

    Set ws(1) = Worksheets("Yearly Lease Order")
    Set ws(2) = Worksheets("Yearly Quote Form")
    Set ws(3) = Worksheets("Yearly Invoice Form")

    For Each v In ws()
    s = Worksheets("Costings Main Menu").Range("C4").Value2
    s = s & " " & v.Name
    If Not WorkSheetExists(s) Then
    v.Copy after:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = s
    End If
    Next v

    Worksheets("Costings Main Menu").Activate
    Range("A1").Select
    End Sub


    'WorkSheetExists in a workbook:
    Function WorkSheetExists(sWorkSheet As String, Optional sWorkbook As String = "") As Boolean
    Dim ws As Worksheet, wb As Workbook
    On Error GoTo notExists
    If sWorkbook = "" Then
    Set wb = ActiveWorkbook
    Else
    Set wb = Workbooks(sWorkbook)
    End If
    Set ws = wb.Worksheets(sWorkSheet)
    WorkSheetExists = True
    Exit Function
    notExists:
    WorkSheetExists = False
    End Function
    Last edited by rikk1965; 12-17-2013 at 04:37 PM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to copy multiple worksheets and then rename them

    Which poster are you refering to?

  7. #7
    Registered User
    Join Date
    12-16-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: VBA to copy multiple worksheets and then rename them

    Sorry. Kenneth Hobson

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA to copy multiple worksheets and then rename them

    IF you just want to copy one sheet, just use one element in the array.

    Obviously you need to change the prefix and sheet name to suit.
    Please Login or Register  to view this content.
    Last edited by Kenneth Hobson; 12-17-2013 at 08:46 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Problem with macro to copy then rename worksheets based on a list
    By Ellen 2Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2013, 01:06 PM
  2. macro to copy a range of worksheets based on cell entry and rename specific sheets
    By Lbischoff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 12:13 PM
  3. Copy and rename worksheets to other workbook but not formulas
    By Oakstream in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2010, 09:27 AM
  4. How do you copy and rename linked worksheets?
    By Phil 51 in forum Excel General
    Replies: 1
    Last Post: 06-06-2006, 11:15 AM
  5. [SOLVED] rename worksheets after copy
    By Qaspec in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1