+ Reply to Thread
Results 1 to 4 of 4

Code optimization to avoid multiple file open calls

  1. #1
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Code optimization to avoid multiple file open calls

    Hello Excel Forum!

    I have a function that opens a file on my network drive and compares a string to the values of the cells in A column. Here is the function:

    Please Login or Register  to view this content.
    I call this function in the following snippet of my macro:
    Please Login or Register  to view this content.
    My situation is this: The "For Each cell" loop is going through a range of 30-100 cells and it calls my function for each cell in the range. That means we're opening and rereading/reparsing the file 30-100 times. Surely, there is a more efficient way for me to do this where I open the file once, compare the values in the A column of my active spreadsheet to the values in the A column of the "Flagged.csv" file and if any value is found in both files to pop up a MsgBox. Any ideas? Here are some sample files for you to work with. Flagged.csv Deposit.csv

    Thank you in advance!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Code optimization to avoid multiple file open calls

    Try this...

    Technically, this is just a sub procedure and not a function as it doesn't return a result. It just displays a message if flagged.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 04-25-2014 at 10:07 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Code optimization to avoid multiple file open calls

    Mind = Blown

    Thank you AlphaFrog! It works perfectly and has a few bits for me to study and learn from!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Code optimization to avoid multiple file open calls

    You're welcome.

+ 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] How to split this long string code in multiple line to avoid an error???
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2013, 10:08 PM
  2. VBA for excel 2003. Open file dialog box, open 2007 file xlsx, continue with code
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2011, 12:12 AM
  3. How to avoid 're-open' alert while opening file
    By excelquestioner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-24-2007, 02:29 PM
  4. Multiple Userforms - Avoid code duplication
    By peter.thompson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2006, 11:25 PM
  5. Speed up pivot table VBA code, avoid multiple recalculations
    By Ronny in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2005, 04:00 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