Results 1 to 4 of 4

Combine 2 worksheets into an existing tab with browsing for files

Threaded View

  1. #1
    Forum Contributor Webbers's Avatar
    Join Date
    09-06-2005
    Location
    Poinciana, FL
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    337

    Combine 2 worksheets into an existing tab with browsing for files

    Okay, I am very new to VBA, and I have managed to teach myself a little with the help of this forum, but I am not sure how to adapt a currently functional script to my current needs.

    The script below is a working script I use, I thought I could adapt it, as my needs are similar, but I am just plain stuck and don't know how to approach this issue.

    Situation: the "Summary" worksheet is in a file that changes name and path each time it is used. The 2 "source data" files also fall under this circumstance. I know the path will change, since I am creating this for someone else, I am unsure if I can control the file names, but if I have a say in it, they will be named "pma1" and "pma2". Neither worksheet will have a specific number of rows of data, they will both be completely random. These reports are both pulled from Cognos and saved as Excel files. Now when the two files are being combined, on the 2nd file (PMA2), row 1 must be excluded, as it contains the same header information that will be listed on "PMA1". Oh, also, the "Summary" tab where the data will be combined to will be a blank worksheet until this macro is used, and will always be open when the macro to combine the 2 PMA files is run.

    Can the code below be revised to meet my needs or is it easier to just scrap it completely and start from scratch?

    Sub CopyAndCombine()
    '
    ' Macro to combine 2 worksheets
    '
        Application.ScreenUpdating = False
        Dim fn, sh As Worksheet
        Set sh = Sheets("Summary")
        fn = Application.GetOpenFilename
        If fn = False Then
            MsgBox "Nothing Chosen", vbCritical, "Select workbook"
        Else
            Workbooks.Open fn
            ActiveSheet.UsedRange.copy sh.[A1]
            ActiveWorkbook.Close False
            ThisWorkbook.Activate
            Application.ScreenUpdating = True
        End If
    End Sub
    Attached Files Attached Files
    ~*~ Sherry ~*~
    Poinciana, FL

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