+ Reply to Thread
Results 1 to 5 of 5

Macro taking too long to execute

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    151

    Macro taking too long to execute

    Greetings all

    I have been working on a macro this week that will insert a row underneath the header and write the formulas to the proper cells so that we can record production in a reasonably efficient manner. I do not claim to be a macro magician and I am sure there are better ways to accomplish some of the things I am doing, but it seem as though this particular macro has taken it upon itself to run too slow to be useful at all. The entire macro, comments and all is only 266 lines long (and there are a lot of comments as I wanted someone else to be able to go in a tell what was going on). It seemed to be working fine yesterday and I have been putting the final formulas in today before working on the formatting. When I tested it before lunch, it froze, so after lunch I ran it in debug mode and it isn't hanging on the back end where I have been working today, but at the very beginning. Can someone please take a look at this and see if there is something I am missing that would cause it to hang up?

    
    Sub Production_Register_Line_Add()
    '
    Dim lrow As Long
    Dim Gm_Lb As Double
    Dim Gm_Oz As Double
    Dim History As Integer
    '*********************************************************************************************
            Sheets("Variance Register").Select
    '*********************************************************************************************
            Range("7:7").Insert shift:=xlDown
            Range("6:6").Copy Range("A7")                                               'This line is taking in excess of 30 seconds to execute
                'On Error Resume Next
            Rows("6").ClearContents
    '*********************************************************************************************
    '   Declare Values for Constants
    '*********************************************************************************************
            lrow = Worksheets("Variance Register").Range("A" & Rows.Count).End(xlUp).Row
            Gm_Lb = 453.5924
            Gm_Oz = 28.349527
            History = 180   'Number of days history to use when calculating Unit Cost Averages
    '*********************************************************************************************
    '
    '   A - Manufacturing Date (date when batch was actually made)
    '   B - Fill Date (Actual Production Date)
    '   C - Batch Number (Number stamped on jars to identify manufacture Batch)
    '   D - Finish Good Number
    '   E - Item Description
    '
        Range("E6").Formula = _
            "=IFERROR(INDEX('\\Network\Company\Product Data\Product Data v1.00.xls'" _
            & "!Item_Desc,MATCH($D6,'\\Network\Company\Product Data\[Product Data v1.00.xls]" _
            & "Product Data'!Item_No,0)),"""")"
    
    ' This index(match()) is also taking in the neighborhood of 30 seconds to execute  and I have 4 of these lookups 
    'more stuff
    end sub
    Right now, I have data going out to column BP and a little over 3,100 rows

    I would appreciate it if anyone could see what I am doing that would cause this thing to hang up like it is.

    Thanks
    Jacob Albers
    Excel 2003 & 2010

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro taking too long to execute

    Try to insert the following lines on your macro to suppress screen updating and display alter.

    Application.screenupdating= 0
    Application.displayalerts= 0

    Application.screenupdating= 1
    Application.displayalerts= 1

  3. #3
    Forum Contributor
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    151

    Re: Macro taking too long to execute

    Thanks for your response!

    I tried it, but without any success. It still took about 4 minutes to execute the macro. One thing I noticed while watching the screen not do anything, was that the program would alternate between being responsive and not responsive. I wasn't trying to do anything else at the time, just watching. I took out the screenupdating statements and tried again and it still alternated between responsive and non responsive.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro taking too long to execute

    I think the cuplrit lines are these
    Range("6:6")
    Rows("6")
    what are these lines? You also have to open your folder and that takes another 30 seconds. This is really weird

  5. #5
    Forum Contributor
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    151

    Re: Macro taking too long to execute

    When I insert the row

    
            Range("7:7").Insert shift:=xlDown
    ' I insert the row 2 rows below my headers so that I copy the formats of the data area and not the formats of the header row.
            Range("6:6").Copy Range("A7")
    ' The Range("6:6").Copy copies the data residing on row 6 and pastes it to row 7 giving me an empty row 6 at the top of the data.
            Rows("6").ClearContents
    ' Rather than a cut/paste of row 6 data to row 7, I have always used a copy then clear data.  Call me paranoid, but if it blew up at that time, I wouldn't need to go back and 
    ' rebuild data, just start over.
    Actually, the file Product Data is almost always already open, so it seldom has to actually open it. It isn't making any sense to me either.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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