Results 1 to 5 of 5

loop through files and copy last column

Threaded View

gsurge loop through files and copy... 05-26-2011, 09:06 AM
watersev Re: loop through files and... 05-26-2011, 09:18 AM
gsurge Re: loop through files and... 05-26-2011, 09:19 AM
watersev Re: loop through files and... 05-26-2011, 09:52 AM
gsurge Re: loop through files and... 05-26-2011, 10:24 AM
  1. #5
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: loop through files and copy last column

    here is my code
    Sub datacollect()
      
    Dim C As Long
      Dim DstWks1 As Worksheet
      Dim DstWks2 As Worksheet
      Dim LastRow As Long
      Dim R As Long
      Dim SrcWkb As Workbook
      Dim StartRow As Long
      Dim wkbname As Variant
      Dim xlsFiles As Variant
      
       'Starting column and row for the destination workbook
        C = 1
        R = 1
       'Set references to destination workbook worksheet objects
        Set DstWks1 = ThisWorkbook.Worksheets("Formdata")
        
       'Starting row on source worksheet
        StartRow = 11
        
       'Get the workbooks to open
        xlsFiles = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", MultiSelect:=True)
        Application.AskToUpdateLinks = False
          If VarType(xlsFiles) = vbBoolean Then Exit Sub
          
         'Loop through each workbook and copy the data to this workbook
          For Each wkbname In xlsFiles
            Set SrcWkb = Workbooks.Open(Filename:=wkbname, ReadOnly:=True)
              LastRow = SrcWkb.Worksheets("Data").Cells(Rows.Count, "BG").End(xlUp).Row
                If LastRow >= StartRow Then
                  With SrcWkb.Worksheets("Data")
                    DstWks1.Cells(R, C).Resize(LastRow - StartRow + 1, 1).Value = _
                    .Range(.Cells(StartRow, "BG"), .Cells(LastRow, "BG")).Value
                  End With
                End If
            C = C + 1
            SrcWkb.Close savechanges:=False
          Next wkbname
          
    End Sub


    Instead of column BG, i would like the last used column
    Last edited by Leith Ross; 05-26-2011 at 12:02 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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