+ Reply to Thread
Results 1 to 6 of 6

Make Macro Run Faster

  1. #1
    Registered User
    Join Date
    02-05-2014
    Location
    Texas
    MS-Off Ver
    Excel 2013
    Posts
    4

    Make Macro Run Faster

    Hey guys. Thanks for taking time to view this thread. This is my first question post, so if I mess something up please let me know.

    Here's an overview of my issue: I have lengthy macro that work perfectly yet takes a while to execute, and I would like to restructure it to execute faster (whether that be deleting unnecessary lines or writing a new macro entirely).

    Further below in this post is the code that I put together to import data from numerous workbooks (each workbook is named "JSRYYYYMMDD.xlsx", where JSR stands for the report type, YYYY is subbed for the year, MM is subbed for the month, and DD is subbed for the day) into one workbook entitled "The Import Book.xlsm".

    The numerous workbooks which the data is pulled from are stored in a folder, and look like this:

    JSR20140203.xlsx (this is the Job Status Rollup for February 3, 2014)
    JSR20140204.xlsx (this is the Job Status Rollup for February 4, 2014)
    JSR20140205.xlsx (this is the Job Status Rollup for February 5, 2014)
    JSR20140206.xlsx (this is the Job Status Rollup for February 6, 2014)
    (etc.)

    When the macro is run, it searches the directory I specified, finds the first file I specify in a cell, copies and pastes over the data I need, closes that file, then moves on to the second file that I've specified and repeats the process until the last file I specify has had its data imported.

    The code you see below runs for each and every file imported. It takes about 10 seconds for the data from one file to be imported to the destination file. So, how can I edit the code below to speed up this process?

    Let me know if I've made anything unclear. Thanks in advance for all the help.

    CODE:

    Please Login or Register  to view this content.
    Last edited by alansidman; 02-06-2014 at 01:35 PM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Make Macro Run Faster

    Hi, quepes13,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    02-05-2014
    Location
    Texas
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Make Macro Run Faster

    Hey, HaHoBe - my fault. Thanks. This should work.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-06-2014
    Location
    Columbus, IN
    MS-Off Ver
    2013/O365
    Posts
    41

    Re: Make Macro Run Faster

    Welcome and firstly put code in code brackets so it's more easily discernable ([/code] to end and
    Please Login or Register  to view this content.
    downside is you get itchy not seeing anything happen.

    oh, and you can use this to Alt-Tab between windows without having to designate exactly which window you're switching to. I dunno if that goes any faster or not tho.
    Please Login or Register  to view this content.
    One of my macros takes a good 40-50 seconds to run partially becaues the file it gets data from is on a network drive. That's if I'm only getting data for one day.
    -Russell

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Make Macro Run Faster

    Hi, quepes13,

    you should not switch between the worbooks but use object to get the data over from one book to the other:

    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    02-05-2014
    Location
    Texas
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Make Macro Run Faster

    Wow. That cut the time by from about 11 seconds per file to about 3. Incredible! I did have to define the ErrorHandler, so the final code can be seen below. I chose cell A1 to be selected at the end just to bring me back to the top of the sheet when the process is over.

    Thanks again Holger for making this happen & also Russell for the screen updating bit (my report looks cleaner now!

    Please Login or Register  to view this content.

+ 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. How to make this macro run faster ?
    By vertigo00 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2012, 02:01 PM
  2. [SOLVED] How to make the macro run faster?
    By ahng in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-19-2012, 11:48 AM
  3. Can I Make My Macro Faster?
    By PIPPIBOOKS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2008, 06:20 PM
  4. How to make macro running faster
    By olio39 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2007, 08:13 AM

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