+ Reply to Thread
Results 1 to 6 of 6

VBA double-loop search and copy

Hybrid View

Old4xford VBA double-loop search and... 07-29-2015, 01:03 PM
Steve7913 Re: VBA double-loop search... 07-30-2015, 10:23 AM
Old4xford Re: VBA double-loop search... 07-30-2015, 12:32 PM
ggs22 Re: VBA double-loop search... 07-30-2015, 10:54 AM
Old4xford Re: VBA double-loop search... 07-30-2015, 12:33 PM
ggs22 Re: VBA double-loop search... 07-30-2015, 01:11 PM
  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    Montreal, Qc, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: VBA double-loop search and copy

    Hi, I didnt open up your files, but i think i understand what your looking for.

    this should help point you in the right direction if nothing else. ( there might be a little bit of additional data that you don't need. i tried to remove it all but i pulled this from one of my old codes.)

    let me know if it works

    Sub Transfer_data_from_Files()
    
    Dim MyPath, MyFileName, MyFolderName
    Dim PATHandFILE, FExist, MyCount, FCount, MySheet
    
    
    '****************************************************************
    ' set path to folders
    
    MyPath = "C:\Users\*your user name*\Desktop\Myfolder"     ' be sure to change the username and the folder where your files are (do not put the main one in same folder)
    
    MyFileName = Dir(MyPath & "\")
    
    
    '****************************************************************
    'count files with in dir
    
    Do While MyFileName <> ""
           MyCount = MyCount + 1
            MyFileName = Dir()
    Loop
    
    FCount = MyCount
    MyCount = 0
    
    '****************************************************************
    'set first file name
    
    MyFileName = Dir(MyPath & "\")
    
    
    '****************************************************************
    ' loop throw each file copy the data
    
    Do While MyFileName <> ""
       PATHandFILE = MyPath & MyFileName
       
        Workbooks.Open Filename:=PATHandFILE
        Workbooks(MyFileName).Activate
        
       For MySheet = 1 To Workbooks(MyFileName).Sheets.Count
            Workbooks(MyFileName).Sheets(MySheet).Range("D1").Copy
            
            ThisWorkbook.Activate
            
            MyRow = Sheet1.Range("A99999").End(xlUp).Row + 1
            Sheet1.Cells(MyRow, 1).Select
            Sheet1.Cells(MyRow, 1).PasteSpecial
        Next
            
        Application.DisplayAlerts = False
        Workbooks(MyFileName).Close
        Application.DisplayAlerts = True
        
        
        MyCount = MyCount + 1
      
        
        
       MyFileName = Dir()
    
    Loop
    
    
    End Sub

  2. #2
    Registered User
    Join Date
    03-12-2014
    Location
    Central Texas
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: VBA double-loop search and copy

    Steve, technically your code did look in the directed folder, took the information I was looking for and copied it to the Master file. However: 1) the code itself was very confusing and I wasn't sure where to interject my example files' to get it to run on the example sheet and 2) when the data was copied to the Master file, it copied over the bottom row instead of in the table.
    Oh! I get it. I need rep--->҉

+ 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. Double click cell - copy data to new sheet - create a list from double clicking
    By kakky in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-04-2015, 11:14 PM
  2. double loop until the end (?)
    By pccamara in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2015, 10:45 AM
  3. Copy double-clicked cell to next empty row in different sheet with each double-click
    By erhathaway in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-25-2013, 12:06 AM
  4. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  5. loop Search, copy paste,next search, copy paste ...
    By Macrodroid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2011, 03:19 AM
  6. a double loop?
    By jimmy1981 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-03-2010, 10:48 AM
  7. If else loop to search data and copy it between workbooks
    By exc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2009, 02:51 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