+ Reply to Thread
Results 1 to 6 of 6

Macro to copy a hidden worksheet to an existing workbook then rename.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Macro to copy a hidden worksheet to an existing workbook then rename.

    Good afternoon,

    I am trying to create a macro that will grab a inactive/hidden worksheet and move it to another existing Excel file, then rename that new sheet according to a cell value.

    I tried searching - and this comes up as something close, but it prompts to ask what name should be assigned, while I want it to be renamed just accordingly to one of the cells. It also copies the active worksheet rather than another predesignated ws. Also, it copies the ws to a new file, rather than an existing one.

    Sub testerer() 
        Dim ws As Worksheet 
        Set ws = ActiveSheet 
        Dim s As String 
        s = InputBox("What would you like to name the new sheet?") 
        ws.Name = s 
    End Sub 
     
    Sub testerest() 
        Dim ws As Worksheet 
        Set ws = ActiveSheet 
        On Error Resume Next 
        ws.Name = [A3].Value 
    End Sub

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro to copy a hidden worksheet to an existing workbook then rename.

    Sub testerest()
        Dim WBook As String
        Dim WSheet As String
        Dim WName As String
        
        WBook = "Destination Workbook.xlsx"
        WSheet = "Hidden Worksheet Name"
        WName = Range("A3").Value
        
        With Sheets(WSheet)
            .Name = WName
            .Move Before:=Workbooks(WBook).Sheets(1)
        End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Re: Macro to copy a hidden worksheet to an existing workbook then rename.

    It seems to just copy the sheet into the file I was working on, rather than the destination file.

    Here is my tweaked code:

    Sub export1splitter()
        Dim WBook As String
        Dim WSheet As String
        Dim WName As String
        
        WBook = "C:\Products\1 Products\Product A\PRICE DATABASE 04 06 16"
        WSheet = "1 Splitter Calculation"
        WName = Range("C3").Value
        
        With Sheets(WSheet)
            .Name = WName
            .Copy After:=Sheets(Sheets.Count)
        End With
    End Sub
    Any help is appreciated!

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to copy a hidden worksheet to an existing workbook then rename.

    You should try something like this:

    Workbooks( Sourceworkbook name ).Worksheets(<the hidden worksheet name>).Copy Before:=Workbooks( target workbook ).Sheets(1)
    Workbooks( target workbook ).Worksheets( the hidden worksheet name ).Name = the new name
    It copies the worksheet before the first worksheet and the renames it
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  5. #5
    Forum Contributor
    Join Date
    04-19-2016
    Location
    Michigan
    MS-Off Ver
    15.0
    Posts
    130

    Re: Macro to copy a hidden worksheet to an existing workbook then rename.

    Can I replace
    .Copy Before:=Workbooks( target workbook ).Sheets(1)
    with:
    .Copy After:=Sheets(Sheets.Count)

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Macro to copy a hidden worksheet to an existing workbook then rename.

    yes, but indicate the workbook too

    .Copy After:=Sheets(Workbooks( target workbookname).Worksheets.Count)

+ 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. Macro to Copy specific worksheet to an existing workbook
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2015, 05:56 PM
  2. Replies: 11
    Last Post: 11-04-2013, 04:32 PM
  3. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  4. Replies: 2
    Last Post: 09-04-2012, 01:19 AM
  5. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  6. Copy and rename a sheet in an existing workbook?
    By robertse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-09-2010, 02:00 PM
  7. copy worksheet that is hidden and rename it using a userfom
    By iscar_marius in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-17-2009, 06:03 AM

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