+ Reply to Thread
Results 1 to 2 of 2

Function to skip the process if the sequence number is missing

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2013
    Location
    chennai,India
    MS-Off Ver
    Excel 2010
    Posts
    75

    Function to skip the process if the sequence number is missing

    Hi All,

    I have a macro to open the files in a folder based on the sequence number mentioned in the program and copy&paste the data in another file.

    Like , open files between 1 to 100.

    But i am getting error while run the macro, because some files were missing between 1 to 100.

    i want to know how to skip this and to proceed with the available files.

    Below the macro i am using:

    HTML Code: 

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Function to skip the process if the sequence number is missing

    Check if the file exists with Dir before trying opening it.
    
    For i = 499 To 598
        strTargetFile1 = "D:\Temp\asnout\etASNOutAT156" & i & ".xml"
        If Len(Dir(strTargetFile)) > 0 Then
            Set wb1 = Workbooks.OpenXML(Filename:=strTargetFile1, LoadOption:=xlXmlLoadImportToList)
            
            Application.DisplayAlerts = False
       
            rownum = rownum + 1
            
            If wb1.Sheets(1).UsedRange.Rows.Count > 1 Then
                wb1.Sheets(1).UsedRange.Rows(2).Copy ThisWorkbook.Sheets("Sheet5").Range("A" & rownum)
            Else
                wb1.Sheets(1).UsedRange.Rows(1).Copy ThisWorkbook.Sheets("Sheet5").Range("A" & rownum)
            End If
    
            wb1.Close False
    
            Application.ScreenUpdating = True 
        End If
    Next i
    Last edited by Norie; 03-15-2014 at 08:38 AM.
    If posting code please use code tags, see here.

+ 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] Indicate missing number in a sequence (Part II)
    By mmock in forum Excel General
    Replies: 3
    Last Post: 02-22-2006, 03:20 PM
  2. [SOLVED] indicate a missing number in a sequence
    By mmock in forum Excel General
    Replies: 13
    Last Post: 02-21-2006, 11:30 PM
  3. [SOLVED] How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  4. [SOLVED] How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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