+ Reply to Thread
Results 1 to 13 of 13

My loop is missing last iteration

Hybrid View

elmnas My loop is missing last... 10-22-2016, 07:43 AM
JohnTopley Re: My loop is missing last... 10-22-2016, 11:10 AM
elmnas Re: My loop is missing last... 10-22-2016, 11:23 AM
WasWodge Re: My loop is missing last... 10-22-2016, 12:40 PM
elmnas Re: My loop is missing last... 10-22-2016, 12:59 PM
YasserKhalil Re: My loop is missing last... 10-22-2016, 01:22 PM
elmnas Re: My loop is missing last... 10-22-2016, 01:29 PM
JohnTopley Re: My loop is missing last... 10-22-2016, 02:09 PM
elmnas Re: My loop is missing last... 10-22-2016, 03:27 PM
JohnTopley Re: My loop is missing last... 10-22-2016, 03:53 PM
elmnas Re: My loop is missing last... 10-22-2016, 04:07 PM
elmnas Re: My loop is missing last... 10-22-2016, 05:58 PM
Richard Buttrey Re: My loop is missing last... 10-22-2016, 06:46 PM
  1. #1
    Forum Contributor
    Join Date
    02-23-2015
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    109

    Re: My loop is missing last iteration

    Quote Originally Posted by JohnTopley View Post
    Your code wasn't looping through the files in the folder

    Try

    Sub test()
        Dim wb As Workbook
        Dim ws As Worksheet
        Dim mRng As Range
        Dim cRng As Range
        Dim mCell As Range
        Dim cCell As Range
    
        Dim filename As String
        Dim folderPath As String
        
        Set Mwb = ActiveWorkbook
        Set mws = Worksheets(1)
        
        lr = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
        
        Set mRng = mws.Range("h1:h" & lr)
        
        folderPath = "C:\DATA\"
        
        file = Dir(folderPath)
        Application.ScreenUpdating = False
        
        While (file <> "")
        
            Set wb = Workbooks.Open(folderPath & file)
            Set ws = wb.Worksheets(1)
            
            lr = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
            
            Set cRng = ws.Range("H1:H" & lr)
                
                For Each mCell In mRng
                        For Each cCell In cRng
                            If cCell = mCell Then mCell.Offset(0, 1) = cCell.Offset(0, 1)
                        Next cCell
                 Next mCell
            
            Workbooks(file).Close SaveChanges:=False
            
            file = Dir
        
        Wend
      
      mws.Range("h1") = mRng
      
      Application.ScreenUpdating = True
    
    End Sub
    Somewhat confused by which column the numbers are in : your code suggests "I", your description "G" and an image "T"!!!

    The comparison loop could be replace by MATCH function.
    The loop is skipping some values strange?

    Here is a link to my DATA folder
    http://www.megafileupload.com/kmyK/DATA.zip

    also for my xlsm file

    http://www.megafileupload.com/kmyM/Loop.xlsm

    Thank you in advance.
    Last edited by elmnas; 10-22-2016 at 11:35 AM.

+ 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. [SOLVED] Go to next loop iteration if current loop has error
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-03-2016, 09:54 PM
  2. VBA - How to continue inner loop while going to next iteration of outer loop?
    By alviniac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2015, 11:21 PM
  3. jump to xth iteration of for next loop
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2015, 12:07 PM
  4. [SOLVED] Last Iteration of Loop?
    By saintplay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2015, 08:19 PM
  5. [SOLVED] Loop fails on 2nd iteration
    By capson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-14-2014, 01:38 PM
  6. Continue next iteration of For loop
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-22-2013, 02:09 AM
  7. Advancing to the next iteration of a loop?
    By Maury Markowitz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2005, 01:06 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