+ Reply to Thread
Results 1 to 2 of 2

Workbook & worksheet combining

Hybrid View

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    7

    Workbook & worksheet combining

    Hello,

    I have regularly use the workbook & worksheet combining macro below.

    I was wondering if it would be possible to edit it in some way to make the macro only combine certain tabs that the user would specifiy the name of.

    As an example, I have about 60 workbooks all containing 4 tabs and wish only to combine the tabs within each workbook called 'red report' is this possible??

    Sub workbook_combine_actual()
    
    'This will copy data from all sheets of the selected workbooks
    'To a sheet named 'Data' in the sheet in which the macro is run from
    
    Dim pasterow As String
    
    mainsheetname = ActiveWorkbook.Name
    
    MsgBox ("Please select spreadsheets to combine")
    filestoopen = Application.GetOpenFilename(MultiSelect:=True)
    
    responseval = MsgBox("Do you want to leave the combined spreadsheets open?", vbYesNo)
    
    Worksheets("Data").Select
    Range("A1").Select
    
    'open workbooks
    For Each w In filestoopen
    
    Workbooks.Open Filename:=w
    copysheetname = ActiveWorkbook.Name
        
        'copy and paste sheets
        For Each sh In Worksheets
        
            sheetnumber = sh.Index
            
            something = Worksheets(sheetnumber).UsedRange.Rows.Count + 1
    
                Worksheets(sheetnumber).UsedRange.Copy
                Workbooks(mainsheetname).Activate
                pasterow = Workbooks(mainsheetname).Worksheets("Data").UsedRange.Rows.Count + 1
            If pasterow = 2 Then
                pasterow = 1
            End If
                Workbooks(mainsheetname).Worksheets(2).Range("A" & pasterow).Select
                ActiveSheet.Paste
                
                Workbooks(copysheetname).Activate
        
        Next sh
    
    If responseval = 7 Then
        Application.DisplayAlerts = False
        ActiveWorkbook.Close
        Application.DisplayAlerts = True
    End If
    
    Next w
    
    Workbooks(mainsheetname).Activate
    
    End Sub
    Thanks for taking the time to read through my query.

  2. #2
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: Workbook & worksheet combining

    [Hi
    Try deleting the codes 1 & 2 & 3 and replace sheetnumber with "red report" in 4 & 5
    1. For Each sh In Worksheets  
    2. sheetnumber = sh.Index
    3. Next sh
    4.Worksheets(sheetnumber).UsedRange.Copy
    5. Workbooks(mainsheetname).Activate
    ravi

+ 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