Results 1 to 9 of 9

Excel Macro search and copy function in subfolders

Threaded View

  1. #1
    Registered User
    Join Date
    10-17-2018
    Location
    k
    MS-Off Ver
    k
    Posts
    5

    Excel Macro search and copy function in subfolders

    Hello everybody,
    i've again some problems with my VBA-Code and hopefully some of you can help me.
    The macro search in a directory after excel files with certain names and then copy the data to another workbook, this works perfect thanks to the hepf of this forum!
    But know, i want that the macro not only copy the data from this folder but als from the subfolders and i struggle to realize that.
    I'm really a newbie in VBA, so if anyone could help me with this, that would be great!

    Here's my code:
    Sub Suchenundkopieren()
    
    Dim directory As String, fileName As String, sheet As Worksheet
    Application.ScreenUpdating = False
    
    directory = "C:\Users\YL\Desktop\Test\*"
    fileName = Dir(directory & "Quell*.xl*")
    
    Tabelle1.Cells.Clear
    
    
        Do While fileName <> ""
    
        Dim src As Workbook
        Dim lr As Long 'Quelle
        Dim lrZiel As Long 'Ziel
        Dim WsZiel As Worksheet
    
            Set WsZiel = ThisWorkbook.Worksheets("Tabelle1")
    
            Set src = Workbooks.Open(directory & fileName, Password:="1234")
    
            lr = src.Worksheets("Overview").Range("A" & src.Worksheets("Overview").Rows.Count).End(xlUp).Row
    
            lrZiel = WsZiel.Cells(WsZiel.Rows.Count, 1).End(xlUp).Row
            If lrZiel <> 1 Then lrZiel = lrZiel + 2
    
            src.Worksheets("Overview").Range("A1:MV" & lr).Copy Destination:=WsZiel.Cells(lrZiel, 1)
    
        src.Close False
    
        Set src = Nothing
        Set WsZiel = Nothing
    
        fileName = Dir
    
        Loop
    
    Application.ScreenUpdating = True
    
    End Sub
    Greetings
    Last edited by alansidman; 11-06-2018 at 01:32 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. macro search in folder and subfolders
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 06-13-2018, 04:15 PM
  2. Replies: 4
    Last Post: 10-21-2016, 05:33 PM
  3. Replies: 1
    Last Post: 10-19-2016, 04:44 PM
  4. Needs macro to copy excel files from folders, subfolders to new folder
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2014, 08:53 AM
  5. Macro to search folder including subfolders for file and open
    By kiraexiled in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2012, 02:45 PM
  6. [SOLVED] Search subfolders in excel 2010
    By greasybob in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-08-2012, 07:03 PM
  7. Replies: 2
    Last Post: 03-26-2012, 07:12 PM

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