+ Reply to Thread
Results 1 to 1 of 1

Choose a folder and loop through all files in the chosen folder

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    110

    Choose a folder and loop through all files in the chosen folder

    Hi,

    Im currently using this code
    Sub CopyDishonours_Click()
    
    Dim vFile As Variant
    Dim wbCopyTo As Workbook
    Dim wsCopyTo As Worksheet
    Dim wbCopyFrom As Workbook
    Dim wsCopyFrom As Worksheet
    Dim Last_Row As Long
    Dim cLast_Row As Long
    Dim wb1 As Workbook
    
    
    Set wbCopyTo = ActiveWorkbook
    Set wb1 = ThisWorkbook
    Set wsCopyTo = wb1.Sheets("Data")
    
        '-------------------------------------------------------------
        'Open file with data to be copied
        
        vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
        "*.xl*", 1, "Select Excel File", "Open", False)
        
        'If Cancel then Exit
        If TypeName(vFile) = "Boolean" Then
            Exit Sub
        Else
        Set wbCopyFrom = Workbooks.Open(vFile)
        Set wsCopyFrom = wbCopyFrom.Worksheets(1)
        End If
        
        '--------------------------------------------------------------
        'Copy Range
        Application.DisplayAlerts = False
        Last_Row = Range("P" & Rows.Count).End(xlUp).Row
        cLast_Row = wb1.Sheets("Data").Range("A2" & Rows.Count).End(xlUp).Row
        wsCopyFrom.Range("P12:B" & Last_Row).SpecialCells(xlCellTypeVisible).Copy
        wsCopyTo.Activate
        Range("A1").Offset(cLast_Row, 0).Select
        Selection.PasteSpecial xlPasteValues
          
           
        'Close file that was opened
        Application.DisplayAlerts = False
        wbCopyFrom.Close SaveChanges:=False
        
    
    End Sub
    I would like to know how I can a folder and loop the code above through all the files in the chosen folder.
    Attached Files Attached Files
    Last edited by smartbuyer; 02-11-2016 at 08:37 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. Replies: 1
    Last Post: 01-28-2019, 06:55 PM
  2. [SOLVED] Loop Through Folder, Create Emails with Sub Folder Names in Subject, Attach files in sub
    By Rschwar23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 10:06 AM
  3. [SOLVED] Open excel files from chosen folder
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-30-2015, 03:57 AM
  4. Replies: 12
    Last Post: 03-09-2015, 05:52 PM
  5. macros to allow me to choose what files i want in same folder?
    By taimysho0 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2014, 08:10 PM
  6. Macro to choose folder and cycle through all files
    By Mr.Pinches in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2011, 04:04 PM

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