+ Reply to Thread
Results 1 to 1 of 1

Extrat data from file & paste into a particular tab in another file

  1. #1
    Registered User
    Join Date
    05-14-2015
    Location
    Canada
    MS-Off Ver
    2013
    Posts
    1

    Post Extrat data from file & paste into a particular tab in another file

    Hi,

    I have a folder that contains multiple files that I want to merge into a master file which has a tab for each file in the folder.

    Step-by-Step

    1. Open first file in the folder
    2. Copy the contents of the file
    3. Close the file
    4. Search the master file for the tab that has the file name
    5. Paste data in that tab starting from cell B1
    6. Repeat for all files in the folder



    I am not sure if the code for finding the proper tab/pasting in the data is correct... Can anyone help me out?




    So far this is my code:

    Sub ImportCommercialData()


    Dim FolderPath As String
    Dim Filpath As String
    Dim Filename As String

    'Defines the path to the folder
    FolderPath = "C:\Users\Desktop\Internal Accounts\Commercial\"

    'Defines the path to the file
    Filepath = FolderPath & ".xlsx"

    'Stores the name of the file
    Filename = Dir(Filepath)

    Dim LastRow As Long
    Dim LastColumn As Long

    'Do While there is a file name
    Do While Filename <> ""
    Workbooks.Open (FikderPath & Filename)

    'Finds last row/column in the opened file
    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    LastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

    'Copies the data range
    Range(Cells(1, 1), Cells(LastRow, LastColumn)).Copy

    'Disables alerts
    Application.DisplayAlerts = False
    'Closes the workbook
    Avtiveworkbook.Close

    'Searches for the proper tab to paste the data in
    Dim wkst As Worksheets

    For Each wkst In ThisWorkbook.Sheets
    If (wkst.Name = Filename) Then
    'Paste into workheet starting from cell B1. I know this doesn't work..
    Activeworksheet.Paste

    Filename = Dir
    End If


    Next

    Loop

    Application.DisplayAlerts = True


    End Sub
    Last edited by Ghoti_ca; 05-14-2015 at 02:03 PM.

+ 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. first copy data from each excel file and paste it to another file.
    By amarjeet.it in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-16-2013, 06:24 AM
  2. Macro that helps copying filtered data in file A and paste to file B ?
    By achimeda in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2013, 02:14 AM
  3. Replies: 3
    Last Post: 05-21-2013, 08:22 AM
  4. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  5. Open the latest file to copy and paste data in another file
    By mmf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2008, 10:41 AM

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