fluffyvampirekitten
Board Regular
- Joined
- Jul 1, 2015
- Messages
- 72
I have this line of codes
however , my excel will lag and most of the time it will stop responding .
Why?
Cross Ref: How to speed up this index match function
Any suggestion ?
however , my excel will lag and most of the time it will stop responding .
Why?
Cross Ref: How to speed up this index match function
Any suggestion ?
Code:
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