+ Reply to Thread
Results 1 to 5 of 5

macro code taking too much times to create various workbooks

  1. #1
    Forum Contributor
    Join Date
    12-23-2012
    Location
    Pakistan
    MS-Off Ver
    Microsoft office LTSC professional plus 2021 version 2403 (Build 17425.20176)
    Posts
    365

    macro code taking too much times to create various workbooks

    this code taking too much time for creating three workbooks, is there any change which creates the workbook in less time, in the workbook, as an example I have attached small version of book but it has about 8 columns and 411000 rows, i'm running office 2016 professional. through pivot table it takes about two minutes for creating three workbooks in a folder. Please see what's wrong with the code.
    Attached Files Attached Files

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: macro code taking too much times to create various workbooks

    One reason is because you are copying the entire workbook each time you execute this line of code.
    Please Login or Register  to view this content.
    That line will not exclude the hidden rows. To exclude the hidden rows use this syntax.
    Please Login or Register  to view this content.
    Another reason for the time consumption is the formatting. As long as you do the formatting on the fly, it will add a couple of seconds per execution because of the size of the file.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: macro code taking too much times to create various workbooks

    Seems like you could also simplify the logic used. You use an advanced filter to get unique values from the column set to a range, then later filter the same column range by each unique value to move sets of data.

    Dealing with range objects in large data sets is slow, you want to use arrays whenever possible. Copy/Paste is extremely slow with large data sets, instead dump a range from source into an array then dump array into destination range.

    I also recall off the top of my head Excel 2016 having issues with not clearing filters prior to removing them.

    I dont have time today to work out some code on this, but if you could post a description of what you want to accomplish (not what the current code does) I can try putting something together that is more efficient at scale.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  4. #4
    Forum Contributor
    Join Date
    12-23-2012
    Location
    Pakistan
    MS-Off Ver
    Microsoft office LTSC professional plus 2021 version 2403 (Build 17425.20176)
    Posts
    365

    Re: macro code taking too much times to create various workbooks

    Thanks Mr JLGWhiz for replying, after replacing this line of code
    "rngFilter.SpecialCells(xlCellTypeVisible).EntireRow.Copy"

    with this

    "rngFilter.EntireRow.Copy"

    the time has reduced to 5 minutes, Thank you very much for your help

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: macro code taking too much times to create various workbooks

    Quote Originally Posted by geniusufo007 View Post
    Thanks Mr JLGWhiz for replying, after replacing this line of code
    "rngFilter.SpecialCells(xlCellTypeVisible).EntireRow.Copy"

    with this (Reversed)

    "rngFilter.EntireRow.Copy"

    the time has reduced to 5 minutes, Thank you very much for your help
    You are welcome,
    regards, JLG

+ 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. Replies: 0
    Last Post: 07-04-2014, 09:53 AM
  2. Replies: 1
    Last Post: 07-26-2013, 11:12 PM
  3. Need macro code for filling values in Sheet 2 by taking input parameters from Sheet1
    By ashaanna88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2012, 09:32 AM
  4. Replies: 1
    Last Post: 09-30-2012, 07:35 PM
  5. Taking into account lead times when ordering
    By Turvy86 in forum Excel General
    Replies: 5
    Last Post: 12-30-2009, 03:57 PM
  6. Taking into account lead times ...
    By Turvy86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-30-2009, 02:25 PM
  7. Need VB Code to Create new workbooks out of a list on one workbook
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2009, 02:29 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