+ Reply to Thread
Results 1 to 3 of 3

code slows down when forced to handle massive data

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    Berlin
    MS-Off Ver
    2013 64bit
    Posts
    2

    Question code slows down when forced to handle massive data

    I am sitting in front of some vba codes I have written with a friend of mine. We have a lot of data and are stucked with the performance. Maybe one of you can help us.

    We are running a macro mainly based on array formulas with a lot of references a look ups to different cells. For example we have this code, which runs quite fast ( ~ 20 sec.) with 10k data but slows down to > 4 min. with 30k data. Does anyone have an idea what the problem is or how to solve?

    I hope we have written the code appropriate:

    Sub test()
    
    Dim i As Integer
    Dim h As Long
    Dim e As Long
    Dim t As Long
    
    Range("clear_RO").Clear
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    Worksheets("s_RO").Calculate
    
    
    t = Range("ts_RO").Value2
    
    ActiveWorkbook.Names.Add Name:="drange_RO", RefersToR1C1:= _
            "=OFFSET(z_RO,1,0,ts_RO,1)"
    
    ActiveWorkbook.Names.Add Name:="vrange_RO", RefersToR1C1:= _
            "=OFFSET(w_RO,1,0,ts_RO,1)"
            
    ActiveWorkbook.Names.Add Name:="phvrange_RO", RefersToR1C1:= _
            "=OFFSET(phv_RO_sim,1,0,ts_RO,1)"
            
    ActiveWorkbook.Names.Add Name:="darange_RO", RefersToR1C1:= _
            "=OFFSET(da_RO_sim,1,0,ts_RO,1)"
            
    ActiveWorkbook.Names.Add Name:="intrange_RO", RefersToR1C1:= _
            "=OFFSET(int_RO_sim,1,0,ts_RO,1)"
    
    ActiveWorkbook.Names.Add Name:="tdrange_RO", RefersToR1C1:= _
            "=OFFSET(tr_RO_sim,1,0,ts_RO,1)"
    
    
    
    'phv
    Dim rng_phv_RO As Range
    Set rng_phv_RO = Range("phvrange_RO")
    
    Range("phvrange_RO").Select
    
        With Sheets("s_RO")
            
        With .Range("phv_RO_sim").Offset(1, 0)
                .FormulaArray = "=MAX(if(drange_RO >= RC[-11] - tlim_RO,if(drange_RO < RC[-11] , vrange_RO)))"
                .AutoFill rng_phv_RO
        End With
        End With
        
    Selection.Calculate
    Selection = Selection.Value2
        
        
    'da
    Dim rng_da_RO As Range
    Set rng_da_RO = Range("darange_RO")
    
    Range("darange_RO").Select
    
        With Sheets("s_RO")
            
        With .Range("da_RO_sim").Offset(1, 0)
                .FormulaArray = "=if(RC[-1] - RC[-11] >= dlim_RO_RO,1,0)"
                .AutoFill rng_da_RO
        End With
        End With
        
    Selection.Calculate
    Selection = Selection.Value2
    
    'intrange
    Dim rng_int_RO As Range
    Set rng_int_RO = Range("intrange_RO")
    
    Range("intrange_RO").Select
    
        With Sheets("s_RO")
            
        With .Range("int_RO_sim").Offset(1, 0)
                .FormulaArray = "=t_RO - IF((t_RO - int_sw_RO - RC[-12])<0,ROUNDDOWN((t_RO - int_sw_RO - RC[-12])/c_RO,0),ROUNDUP((t_RO - int_sw_RO - RC[-12])/c_RO,0))*c_RO"
                .AutoFill rng_int_RO
        End With
        End With
    
    Selection.Calculate
    Selection = Selection.Value2
        
        
    'td
    Dim rng_td_RO As Range
    Set rng_td_RO = Range("tdrange_RO")
    
    Range("tdrange_RO").Select
    
        With Sheets("s_RO")
            
        With .Range("tr_RO_sim").Offset(1, 0)
                .FormulaArray = "=IF(AND(IF(RC[-1]+ tb_RO -RC[-13]>=0,1,0)=1,RC[-2]=1),1,0)"
                .AutoFill rng_td_RO
        End With
        End With
        
    Selection.Calculate
    Selection = Selection.Value2
    
    Application.ScreenUpdating = True
        
    Application.Calculation = xlAutomatic
    
    End Sub
    Last edited by quickhoox; 09-12-2014 at 11:07 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: code slows down when forced to handle massive data

    Please wrap your code in code tags.

    Edit the post, select the code, and press the # button

    At first glance I would say set this to false at the beginning of the code. You have it set to true at the start AND at the end, should be false at the start.
    Application.ScreenUpdating = True

    It will go a lot faster.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    Berlin
    MS-Off Ver
    2013 64bit
    Posts
    2

    Re: code slows down when forced to handle massive data

    Thanks for the tip. quite convneient the # botton.

    Yes, we had the application screen updating as False. little mistake while copy paste

+ 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. Speed up macro - shapes slows code
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2014, 01:29 PM
  2. [SOLVED] VBA code suddenly slows Excel to a crawl...
    By Taemex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2013, 11:46 PM
  3. Massive Array needed....in code
    By jasonsweeney in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-01-2005, 11:05 AM
  4. [SOLVED] Code slows down after a few runs
    By Diverse Computing in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2005, 12:05 AM
  5. [SOLVED] PrintPreview slows Code Execution
    By Don Lloyd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2005, 08:06 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