+ Reply to Thread
Results 1 to 3 of 3

VBA- copy template based on tabs in another sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-01-2014
    Location
    DC
    MS-Off Ver
    Excel 2010
    Posts
    1

    VBA- copy template based on tabs in another sheet

    Hey there,

    I am so so new to VBA and having some issues that aren't as cut and dry as I had hoped they would be.

    Essentially, what I need to do is copy a template to create the same number of worksheets that exist in another workbook. For example, I get a workbook (we'll call it NovemberData.xls) each month with worksheets in it for states (different state data comes in each month). What I would like to do is create a macro that copies a template into a new workbook (call it NovemberReport.xls) and worksheet, and loops to repeat this for each tab in the NovemberData.xls workbook. I would like the worksheet names in NovemberReport.xls to match the worksheet names in NovemberData.xls.

    I had previously gotten it to work where I create a copy of the template based on a list, but since the list changes month to month, I thought it would be more efficient to figure out how to do this where it looped through the tabs that were present instead.

    Anyone have any ideas? super grateful for any help!

    -Mack

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: VBA- copy template based on tabs in another sheet

    Why not make the list dynamic, then you dont have to change the already built VBA?

    By that I mean, have a macro that first lists all the tabs, then recretes them in the new workbook? It sounds like you already have the second part done so you just need VBA to help create the list of worksheets right?
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: VBA- copy template based on tabs in another sheet

    Sub ListWorkSheetNames()
    'Declare Variables
    Dim xWs As Worksheet
    'Define Variables
    Set xWs = Application.ActiveSheet
    'Loop
    For i = 1 To Application.Sheets.Count
         xWs.Range("A" & i) = Application.Sheets(i).Name
    Next i
    End Sub

+ 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. Replies: 1
    Last Post: 11-01-2014, 11:48 AM
  2. Macro to copy a sheet/template in a based on numerical cell value or list
    By hodda in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-10-2013, 03:11 PM
  3. Replies: 11
    Last Post: 05-12-2013, 11:30 AM
  4. [SOLVED] Copy a sheet (from template) to a new sheet, and rename (based on cell value)
    By Siglen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2012, 10:19 AM
  5. Replies: 0
    Last Post: 07-25-2012, 05:40 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