+ Reply to Thread
Results 1 to 11 of 11

Combine multiple worksheets into one with rename

  1. #1
    Registered User
    Join Date
    10-07-2013
    Location
    Somewhere, USA
    MS-Off Ver
    Excel 2013
    Posts
    36

    Combine multiple worksheets into one with rename

    I have the following code that will combine multiple worksheets into one. What I was looking for was an alteration to this code or an additional macro to name each tab of the combined workbook to the file name of the original file. For example, 3 worksheets titled property1, property2, property3 all having 1 tab named sheet1. When combined new workbook will have a file name of Book1 with worksheet names of property1, property 2, and property 3. Any help in this will help greatly.
    if more info in needed please ask and I will be prompt to respond. Thanks in advance,
    -J
    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Combine multiple worksheets into one with rename

    Try something like this..

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    10-07-2013
    Location
    Somewhere, USA
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Combine multiple worksheets into one with rename

    Returns an error
    "Compile Error: Wrong number of arguments or invalid property assignment"

    If there is more information you need to assist you in fixing this error let me know and I'll answer whatever you need. Thanks again.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Combine multiple worksheets into one with rename

    Sorry. A last minute edit created bad syntax. Try this line...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-07-2013
    Location
    Somewhere, USA
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Combine multiple worksheets into one with rename

    Sorry to seem ungrateful when it names the tabs from the file names I am left with an odd name. For example if the original file was named Property1 when combined into the worksheet the associated tab is named "Property1 Sheet1 (2)". Is it possible to have it's name be just "Property1"?

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Combine multiple worksheets into one with rename

    What happens if the workbook Property 1 has more that one sheet? If they always have just one sheet, then you wouldn't need to use For Each Sheet... Next

    Otherwise, remove the green part of the code...
    .Name = Left(Filename, InStr(1, Filename, ".xl", 1) - 1) & " " & .Name

    This would error if there was more than one sheet in the source workbook.

  7. #7
    Registered User
    Join Date
    10-07-2013
    Location
    Somewhere, USA
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Combine multiple worksheets into one with rename

    Good catch. I failed to mention each file will contain only one sheet.

  8. #8
    Registered User
    Join Date
    10-07-2013
    Location
    Somewhere, USA
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Combine multiple worksheets into one with rename

    Works like a charm. Thank you so much.

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Combine multiple worksheets into one with rename

    Quote Originally Posted by damaniam View Post
    Works like a charm. Thank you so much.

    You're welcome. Here's the code cleaned up a bit.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-07-2013
    Location
    Somewhere, USA
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Combine multiple worksheets into one with rename

    Unforseen Problem. Apparently some workbook contains more than one worksheet. Good note is only the first sheet is needed. Is it possible to make this work still?

  11. #11
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Combine multiple worksheets into one with rename

    Quote Originally Posted by damaniam View Post
    Unforseen Problem. Apparently some workbook contains more than one worksheet. Good note is only the first sheet is needed. Is it possible to make this work still?
    Remove the for each sheet loop.

    The cleaned up code above in #9 only copies the first sheet regardless if there are multiples.

+ 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] VBA to copy multiple worksheets and then rename them
    By rikk1965 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-17-2013, 08:43 PM
  2. Required Macro for combine multiple workbooks which contains multiple worksheets
    By DHANASEKARAN in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2013, 03:20 PM
  3. [SOLVED] Macro to combine multiple cells from multiple worksheets into one worksheet
    By sharpmarc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-20-2013, 02:42 PM
  4. [SOLVED] VBA to create multiple worksheets, rename, and insert information all off main sheet ...
    By headstrong2740 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-03-2012, 10:24 AM
  5. [SOLVED] Using Combine macro to combine multiple worksheets - need to modify to paste formulas
    By DLSmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2012, 09:07 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