+ Reply to Thread
Results 1 to 9 of 9

Copying a worksheet from a workbook and save it as a new worksheet based on a list. VBA

  1. #1
    Registered User
    Join Date
    07-03-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    24

    Copying a worksheet from a workbook and save it as a new worksheet based on a list. VBA

    Hi guys

    I am working on a workbook (excel 2010) with 2 sheets. First sheet (List) contains the list of names in column B and C. The second sheet (CIS & FMS data) is the template I want to copy.

    The entries in the list will be up to 1000 entries.

    My request is to create a macro that copies the sheet (CIS & FMS data) x number of entries in the list. I do not want to copy the sheet 'List'. I also DO NOT want to copy the macro in to the newly created sheets.

    Helpful if I can save each newly created worksheets with the names from Column B and C. For example the naming of each sheet is the combined name from column B&C. So the first sheet will be named 'AH15/100 Name -A' and so on.

    Below is the first few lines of the list
    Column B Column C
    AH15/100 Name - A
    AH15/101 Name - B
    AH15/102 Name - C
    AH15/103 Name - D



    I also would like to automatically save the sheets in to a destination folder.


    Thanks guys


    Below is the macro I made from copying and amending existing macros from other sources but not working at all

    Sub CreateWBs()
    Dim lRow, x As Integer
    Dim wbName As String
    Dim MyRange As Range
    Dim Sheet As Range


    Set MyRange = Sheet("List").Range("B5")
    lRow = Range("B" & Rows.Count).End(xlUp).Row
    x = 1
    Do
    x = x + 1
    wbName = Range("B" & x).Value & "_" & Range("C" & x).Value
    ThisWorkbook.ActiveSheet.Copy
    ActiveWorkbook.SaveAs Filename:=" H:\Desktop\to upload TRIM\" & wbName & ".xls"
    Loop Until x = lRow
    ActiveWorkbook.Close


    End Sub

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    You could try this.

    Please Login or Register  to view this content.
    If you want the Workbooks saved to the Desktop, replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Note: Change the forwards slashes (/) as in AH15/100 to something acceptable in File Names. Maybe an underscore (_)
    If you need code to replace these in many cells, let us know.

    Easy to change if needed.

    Please Login or Register  to view this content.
    Last edited by jolivanes; 10-29-2015 at 02:50 AM. Reason: Replace forward slash

  3. #3
    Registered User
    Join Date
    07-03-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    Thanks jolivanes

    I have tried the code but it is coming up with a message box saying " Object doesn't support this property or method".

    But the code to change '/' to '_' is working perfectly.

    Can you please help further

    Thank you

    malitec

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    Can you attach a small example of your actual workbook.
    Change all data that should not be seen by other people, in other words, sanitize before attaching.
    It needs to be exactly like your original as far as sheet names etc is concerned.

  5. #5
    Registered User
    Join Date
    07-03-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    Thanks jolivanes

    Please see attached zip file.

    Thank you

    malitec
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    My bad. Forgot the Sheet name at the 2nd half of this line.
    I have not checked your attachment yet because I think that this is the problem.
    Could you change it and let me know if it works please.
    Sorry about this.
    Change this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    Another line needed it.
    This should do it.
    Again, my apologies
    Please Login or Register  to view this content.
    BTW. Select your 2nd sheet and go Ctrl + End
    That is a big sheet. Maybe slim that down. (Google "Bloated excel file" or something similar)
    Attached Files Attached Files
    Last edited by jolivanes; 10-30-2015 at 02:33 AM.

  8. #8
    Registered User
    Join Date
    07-03-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    Thanks jolivanes .its working. Appreciating your effort. You are a gem

    Thanks

    malitec

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Copying a worksheet from a workbook and save it as a new worksheet based on a list. VB

    Nice to hear that it's working to your liking.
    Good luck

+ 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. Copying cells dynamically to a worksheet based on values in another worksheet
    By freelance in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-10-2013, 01:45 PM
  2. Replies: 3
    Last Post: 01-23-2013, 02:42 PM
  3. Replies: 2
    Last Post: 12-13-2012, 01:10 AM
  4. [SOLVED] Save Every Worksheet in a Workbook to individual PDF files that use the worksheet name
    By schmidt62 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2012, 12:00 AM
  5. [SOLVED] Copy certain cells before save from a worksheet in one workbook to a worksheet in another
    By Marianne Rachmann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2012, 07:16 PM
  6. Replies: 1
    Last Post: 08-21-2012, 08:56 AM
  7. Copying filtered data from one worksheet to a worksheet in another workbook
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2011, 09:13 AM
  8. Replies: 5
    Last Post: 05-19-2010, 04:52 PM

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