Results 1 to 6 of 6

Thread: Macro to copy data from a set of excel files

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Macro to copy data from a set of excel files

    i need to copy specific cell from a set of files inisde a folder and need to be pasted one below other,

    folder. e:\billing\bill\imported
    cells to copy j4, b5, j10, c4
    and j4 value to be pasted in a column of result sheet one below another, b5 on b column, j10 on c column and following. please help me

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Sreejesh, is this only one folder, or does it include sub folders also? will there be excel workbooks only in that folder? and what about the master workbook? will this also be inside this folder?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    it is only one folder, no sub folder and only excel work books. master also inside same folder

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi Sreejesh,

    Welcome to ExcelFox !!

    try this

    Code:
    Sub kTest()
        
        Dim wbkSource   As Workbook
        Dim wbkMaster   As Workbook
        Dim wksMaster   As Worksheet
        Dim Dest        As Range
        Dim FName       As String
        Dim i           As Long
        Dim k(), x
        
        '// User settings
        Const MyFolder = "E:\billing\bill\imported\"
        Const MyCells = "J4,B5,J10,C4"
        Const MasterSht = "Sheet1"
        'End
        
        If Len(Dir(MyFolder, vbDirectory)) Then
            Set wbkMaster = ThisWorkbook
            On Error Resume Next
            Set wksMaster = wbkMaster.Worksheets(MasterSht)
            If Err.Number <> 0 Then
                MsgBox "Master sheet '" & MasterSht & "' couldn't found", vbInformation
                Err.Clear
                Exit Sub
            End If
            On Error GoTo 0
            With Application
                .ScreenUpdating = False
                .DisplayAlerts = False
            End With
            Set Dest = wksMaster.Range("a" & wksMaster.Rows.Count).End(3)(2)
            x = Split(MyCells, ",")
            ReDim k(UBound(x))
            
            FName = Dir(MyFolder & "*.xls*")
            Do While FName <> vbNullString
                If FName <> wbkMaster.Name Then
                    Set wbkSource = Workbooks.Open(MyFolder & FName, 0)
                    With wbkSource.Worksheets(1)
                        For i = 0 To UBound(x)
                            k(i) = .Range(CStr(x(i))).Value
                        Next
                    End With
                    wbkSource.Close 0
                    Set wbkSource = Nothing
                    Dest.Resize(, UBound(x) + 1) = k
                    Set Dest = Dest(2)
                End If
                FName = Dir()
            Loop
        End If
        With Application
            .ScreenUpdating = 1
            .DisplayAlerts = 1
        End With
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    this is working thanks a lot

  6. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    You are welcome and thanks for the feedback
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Replies: 9
    Last Post: 05-31-2013, 11:31 PM
  2. Replies: 0
    Last Post: 04-20-2013, 10:07 AM
  3. Macro to copy data in specific Columns
    By Howardc in forum Excel Help
    Replies: 0
    Last Post: 04-19-2013, 10:42 AM
  4. Replies: 2
    Last Post: 11-08-2012, 01:15 PM
  5. Macro for Opening files and copy the contents of the File
    By ravichandavar in forum Excel Help
    Replies: 16
    Last Post: 08-15-2012, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •