+ Reply to Thread
Results 1 to 6 of 6

How to speed up this index match function

Hybrid View

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    66

    How to speed up this index match function

    I have these lines of codes and this macro runs really slow until it stop responding at some point of time
    Any suggestion to speed up this macro ?
    Both files are dynamic.


    Any idea?[/COLOR]
    Private Sub Unsuccessful()
    'Update Column S and T
    'S = Active Ext ID , T = Inactive Ext ID
    
    Dim MaxRowNum As Long
    
    Sheets("SimPat").Select
    
    'Set up an Error handler
    On Error GoTo errorFound
    Err.Clear
    On Error GoTo 0
    
        
    'Vlookup/IndexMatch Active Ext ID
    Range("S2").FormulaR1C1 = _
          "=INDEX('[PatientMerge.xls]2015'!C10,MATCH(C[-16],'[PatientMerge.xls]2015'!C10,0))"
    
    'Vlookup/IndexMatch Inactive Ext ID
    Range("T2").FormulaR1C1 = _
          "=INDEX('[PatientMerge.xls]2015'!C11,MATCH(C[-17],'[PatientMerge.xls]2015'!C11,0))"
        
        
        'Locate last filled row in column S (this instead of the loop)
        MaxRowNum = Range("S" & Rows.Count).End(xlUp).Row
     
        
        'Autofill the rest of the rows
        Range("S2:T2").Select
        Selection.AutoFill Destination:=Range("S2:T2" & MaxRowNum), Type:=xlFillDefault
        'Column S and T Autofit
        Columns("S:T").Select
        Columns("S:T").EntireColumn.AutoFit
                
        'Copy and Paste data as value
        Sheets("SimPat").Select 'Activate/Open Simpat again
        Range("S2:T2" & MaxRowNum).Select
        Selection.Copy
        Worksheets("Simpat").Range("U2:V2" & MaxRowNum).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
           :=False, Transpose:=False
           
        Columns("S:S").Select
        Selection.Delete Shift:=xlToLeft
        Columns("T:T").Select
        Selection.Delete Shift:=xlToLeft
           
        Application.CutCopyMode = False
        
    With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
    End With
    
    
    'Close the error Handler
    Exit Sub
    errorFound:
    If Err.Number > 0 Then MsgBox Err.Description, vbCritical, "Error#: & Err.Number"
    Err.Clear
    
    End Sub
    Really need it urgently

    Cross Ref: http://www.mrexcel.com/forum/excel-q...ml#post4226694



    Just updated my code cos the copy/paste and autofill wasnt working properly.
    However it is still running slow


    Private Sub Unsuccessful3()
    
    'Update Column S and T
    'S = Active Ext ID , T = Inactive Ext ID
    Dim MaxRowNum As Long
    With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
    End With
    Sheets("SimPat").Select
    'Set up an Error handler
    On Error GoTo errorFound
    Err.Clear
    On Error GoTo 0
        'Locate last filled row in column S (this instead of the loop)
        MaxRowNum = Range("C" & Rows.Count).End(xlUp).Row
        
    'Vlookup/IndexMatch Active Ext ID
    Range("S2:S" & MaxRowNum).Formula = "=INDEX('[PatientMerge.xls]2015'!$J:$J,MATCH(C:C,'[PatientMerge.xls]2015'!$J:$J,0))"
    'Vlookup/IndexMatch Inactive Ext ID
    Range("T2:T" & MaxRowNum).Formula = "=INDEX('[PatientMerge.xls]2015'!$K:$K,MATCH(C:C,'[PatientMerge.xls]2015'!$K:$K,0))"
        Columns("S:T").EntireColumn.AutoFit
                
        'Copy and Paste data as value
        Sheets("SimPat").Range("S2:T" & MaxRowNum).Copy
        Sheets("SimPat").Range("S2:T" & MaxRowNum).PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
    End With
    'Close the error Handler
    Exit Sub
    errorFound:
    If Err.Number > 0 Then MsgBox Err.Description, vbCritical, "Error#: & Err.Number"
    Err.Clear
    
    End Sub
    Last edited by fluffyvampirekitten; 07-27-2015 at 03:05 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to speed up this index match function

    Try this...

    Private Sub Unsuccessful()
    Dim MaxRowNum As Long
    
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    
    With Sheets("SimPat")
        .Range("S2").FormulaR1C1 = _
              "=INDEX('[PatientMerge.xls]2015'!C10,MATCH(C[-16],'[PatientMerge.xls]2015'!C10,0))"
        .Range("T2").FormulaR1C1 = _
              "=INDEX('[PatientMerge.xls]2015'!C11,MATCH(C[-17],'[PatientMerge.xls]2015'!C11,0))"
        MaxRowNum = .Range("S" & Rows.Count).End(xlUp).Row
        .Range("S2:T2").AutoFill Destination:=.Range("S2:T2" & MaxRowNum), Type:=xlFillDefault
        .Columns("S:T").EntireColumn.AutoFit
        .Range("S2:T2" & MaxRowNum).Copy
        .Range("U2:V2" & MaxRowNum).PasteSpecial Paste:=xlPasteValues
        .Columns("S:S").Delete Shift:=xlToLeft
        .Columns("T:T").Delete Shift:=xlToLeft
        Application.CutCopyMode = False
    End With
    
    With Application
        .Calculation = xlCalculationAutomatic
        DoEvents
        .ScreenUpdating = True
    End With
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    66

    Re: How to speed up this index match function

    Quote Originally Posted by :) Sixthsense :) View Post
    Try this...

    Private Sub Unsuccessful()
    Dim MaxRowNum As Long
    
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    
    With Sheets("SimPat")
        .Range("S2").FormulaR1C1 = _
              "=INDEX('[PatientMerge.xls]2015'!C10,MATCH(C[-16],'[PatientMerge.xls]2015'!C10,0))"
        .Range("T2").FormulaR1C1 = _
              "=INDEX('[PatientMerge.xls]2015'!C11,MATCH(C[-17],'[PatientMerge.xls]2015'!C11,0))"
        MaxRowNum = .Range("S" & Rows.Count).End(xlUp).Row
        .Range("S2:T2").AutoFill Destination:=.Range("S2:T2" & MaxRowNum), Type:=xlFillDefault
        .Columns("S:T").EntireColumn.AutoFit
        .Range("S2:T2" & MaxRowNum).Copy
        .Range("U2:V2" & MaxRowNum).PasteSpecial Paste:=xlPasteValues
        .Columns("S:S").Delete Shift:=xlToLeft
        .Columns("T:T").Delete Shift:=xlToLeft
        Application.CutCopyMode = False
    End With
    
    With Application
        .Calculation = xlCalculationAutomatic
        DoEvents
        .ScreenUpdating = True
    End With
    
    End Sub

    It load quite fast but....
    Oh my god. it seems that it didnt fill up all the rows
    And copy/paste isnt working , any help.

  4. #4
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: How to speed up this index match function

    Hi,

    You have to turn off some Excel functionality so your code runs faster

    Private Sub Unsuccessful()
    'Update Column S and T
    'S = Active Ext ID , T = Inactive Ext ID
    
    Dim MaxRowNum As Long
    
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    
    ‘>>your code goes here<<
    
    Application.ScreenUpdating = True
    Application.DisplayStatusBar = True
    Application.Calculation = xlCalculationautomatic
    Application.EnableEvents = True
    
    End sub
    Thank you

    If I have helped you in someway, use the * icon below to give reputation feedback, it is appreciated.

  5. #5
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: How to speed up this index match function

    The first thing to learn when writing macros is that the Select command should be avoided because it slows it down a lot.

    This is slow code
     Columns("T:T").Select
        Selection.Delete Shift:=xlToLeft


    This is much faster
     Columns("T:T").Delete Shift:=xlToLeft
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  6. #6
    Registered User
    Join Date
    07-01-2015
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    66

    Re: How to speed up this index match function

    Finally it can load faster than before ,
    I also add a few codes to open up the another reference , it seems that it also did a trick .
    THANK YOU SO MUCH! Really appreciated <3

+ 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. Problems applying INDEX-MATCH-MATCH function on other data
    By LennartB in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-13-2015, 05:33 AM
  2. INDEX(MATCH)) / LOOKUPS Processing Calculator Speed
    By AstToTheRegionalMGR in forum Excel General
    Replies: 1
    Last Post: 02-17-2015, 10:57 AM
  3. [SOLVED] Stuck on Match function with #N/A; attempting to reverse Index/Match
    By Cappytano in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-10-2014, 06:39 PM
  4. Replies: 3
    Last Post: 06-17-2013, 12:37 PM
  5. [SOLVED] Help speed up slow INDEX (SMALL function
    By submariner18 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-12-2012, 01:14 PM
  6. Improving Speed of Index and Match Functions
    By hazza147 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-30-2010, 01:05 PM
  7. Match/Index Calcuation Speed
    By Rochy81 in forum Excel General
    Replies: 1
    Last Post: 10-01-2008, 04:19 PM

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