+ Reply to Thread
Results 1 to 3 of 3

Automate bringing tabs together from 2 workbooks

  1. #1
    Registered User
    Join Date
    11-19-2011
    Location
    Shreveport LA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Automate bringing tabs together from 2 workbooks

    I have 2 set of speadsheets. The first one has 2 tabs that has informantion on it. It is sent in with different names to reflect the order number of work done in the field. For instance, the field worked two orders today, the names of the spreadsheets turned in could be 1234 and 5678. The order numbers will never be the same. The second one has 20 tabs. Each tab is named to match the number, I already have a macro to name the tabs. What I need it to do is if the first spreadsheet is named 1234 and one of the tabs in the second spreadsheet will be named 1234 is to take that tab of 1234 and put it in the spreadsheet of 1234 as a tab of 1234. I can do this manually but want to do it with a macro or script. any help will do.

  2. #2
    Registered User
    Join Date
    09-28-2011
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Automate bringing tabs together from 2 workbooks

    Hello, i'm assuming these worksheets are are formatted as lists thus making use of currentregion feasible. Book2 is my database and book1 is the new data you need added to the database (Book2 in my example).

    <code>

    Option Explicit

    Sub data_migrater()

    Dim ws_name As String
    Dim ws As Worksheet, wb As Workbook, db_sheet_names As Variant
    Dim i As Integer, output As Range, wscount, outRow As Long

    With Workbooks("Book2")
    ReDim db_sheet_names(1 To .Worksheets.Count)
    End With

    'array database ws names
    For i = 1 To Workbooks("Book2").Worksheets.Count
    db_sheet_names(i) = Workbooks("Book2").Worksheets(i).Name
    Next i

    'check new additions against array names
    For Each ws In ThisWorkbook.Worksheets
    wscount = 0
    For i = 1 To UBound(db_sheet_names)
    If db_sheet_names(i) = ws.Name Then
    Set output = Workbooks("Book2").Worksheets(db_sheet_names(i)).Cells(Rows.Count, 1).End(xlUp).Offset(1)
    ws.Range("A1").CurrentRegion.Offset(1).copy _
    Destination:=output
    wscount = wscount + 1
    End If
    Next i
    If wscount = 0 Then
    ws.copy After:=Workbooks("Book2").Worksheets(Workbooks("Book2").Worksheets.Count)
    End If
    Next ws
    End Sub
    </code>

    Best,
    Craig

  3. #3
    Registered User
    Join Date
    11-19-2011
    Location
    Shreveport LA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Automate bringing tabs together from 2 workbooks

    I appreciate the post. I am not sure of where to put this code though, would it be a macro and I would just push a button. I am new to coding. also, will this work if the workbooks are not named book 1 and book 2? I have added some attachments to better explain what I need.

    To explain more, I would open all four files. in the file Print_Ticket, there will be tabs named 92345678, 65748322 and 12345678. I need those tabs to be merged in the correct file for the other three. for instance, originally 92345678 only has the tabs of CM1, CM2 and Materials. When it is done, I want it to have the tab of 92345678 too. Also, the only constant is the name of the Print_Ticket file but the tabs will be different numbers and the other three files will also be named different numbers.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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