+ Reply to Thread
Results 1 to 3 of 3

Need help to enhance and improve VBA code. Need to end the operations

Hybrid View

  1. #1
    Registered User
    Join Date
    11-24-2011
    Location
    SINGAPORE
    MS-Off Ver
    MS Office Home & Business 2010
    Posts
    22

    Need help to enhance and improve VBA code. Need to end the operations

    Hello Forum! Good morning! I am very new to the forum and would like help with codes.

    here is my code which I need help with

    this is the middle of the code

    Columns("E:HZ").Select
    Selection.Delete Shift:=xlToLeft
    
    If Len(strFile) Then
    
    Workbooks.Open (strPath & strFile)
     Else
            MsgBox "I am unable to locate file: " & vbCr & vbCr & strPath & "?????PROCESSED.csv", , "File Not Found"
        End If
    
    
        Sheets(1).Select
        Range("A1").Select
        Selection.ClearContents

    What can I do? I need the process (operation) to end if it is unable to locate a file which ends with the word "PROCESSED.csv". Currently, if it is not able to find the required file, it will show the dialog box. This is good. But after i click the "ok" on the dialog box, it continues with the operation which is actually not going to be correct.

    How do i code this so that if it is unable to find the "????PROCESS.csv" file, it will end the operation and will not continue?


    Thank you

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,033

    Re: Need help to enhance and improve VBA code. Need to end the operations

    Maybe:

    Columns("E:HZ").Select
    Selection.Delete Shift:=xlToLeft
    
    If Len(strFile) Then
    
    Workbooks.Open (strPath & strFile)
     Else
            MsgBox "I am unable to locate file: " & vbCr & vbCr & strPath & "?????PROCESSED.csv", , "File Not Found"
    Exit sub
        End If
    
        Sheets(1).Range("A1").Selection.ClearContents
    Never use Merged Cells in Excel

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,243

    Re: Need help to enhance and improve VBA code. Need to end the operations

    Hi Brandon,

    After your MsgBox line put an

    Exit Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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