Consulting

Results 1 to 4 of 4

Thread: Loop fifty files into one file

  1. #1
    VBAX Regular
    Joined
    Dec 2007
    Posts
    26
    Location

    Loop fifty files into one file

    I have fifty files in a folder named TF. Each files are named in numerical order tf1, tf2, tf3 and so on. They already contain data A:e. I need a loop that will open each file and insert corresponding number in column A to the last row of data, and copy all data to a new file. So all fifty files will be one file. thank you.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something like

    [vba]

    Const ROOT_PATH As String = "C:\test\"
    Dim wb As wokbook
    Dim Lastrow As Long
    Dim Nextrow As Long

    Set wb = Workbooks.Add
    Nextrow = 1
    For i = 1 To 50

    Workbooks.Open ROOT_PATH & "tf" & i & ".xls"
    With ActiveWorkbook.Worksheets(1)

    .Cells(.Rows.Count, "A").End(xlUp).Row
    .Rows(1).Resize(Lastrow).Copy wb.Worksheets(1).Cells(Nextrow, "A")
    Nextrow = Nextrow + 1
    End With
    ActiveWorkbook.Close savechanges:=False
    Next i
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Dec 2007
    Posts
    26
    Location
    [vba] .Cells(.Rows.Count, "A").End(xlUp).Row[/vba] I get yellow block for that line of code when I run the macro, and get an error message Run time error 438 "Object doesn't support this object or method". Thank you for your help

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry, it should have been

    [vba]

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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