Help to speed up Macro

dlatha01

Board Regular
Joined
Apr 7, 2009
Messages
65
Hi All,

Any help appreciated to speed up this macro would be greatly appreciated.

Many Thanks

Sub FTSE()

'

' Macro Currently running at 42 seconds

Application.ScreenUpdating = False

Application.EnableEvents = False

Range("V11").Select

Selection.FormulaArray = _

"=IFERROR(INDEX(Ftse!C[-4],MATCH(MAX(IF(RC[-21]=Ftse!C[-20],Ftse!C[-16])),IF(RC[-21]=Ftse!C[-20],Ftse!C[-16]),0)),0)"

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("W11").Select

Selection.FormulaArray = _

"=IFERROR(INDEX(Ftse!C[-15],MATCH(MAX(IF(RC[-22]=Ftse!C[-21],Ftse!C[-17])),IF(RC[-22]=Ftse!C[-21],Ftse!C[-17]),0)),0)"

Selection.FormulaArray = _

"=IFERROR(INDEX(Ftse!C[-15],MATCH(MAX(IF(RC[-22]=Ftse!C[-21],Ftse!C[-17])),IF(RC[-22]=Ftse!C[-21],Ftse!C[-17]),0)),0)"

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Range("X11").Select

ActiveCell.FormulaR1C1 = _

"=INDEX(Positions!C[-22],MATCH([@[FundID]],Positions!C[-16],0))"

Range("X11").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Application.EnableEvents = True

Application.ScreenUpdating = True

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Getting rid of "Select" and Selection" statements can help speed up your code. Try this:
VBA Code:
Sub FTSE()

    Dim lrv As Long, lrw As Long, lrx As Long

    Application.ScreenUpdating = False
    Application.EnableEvents = False

'   Find last row in column V with data
    lrv = Cells(Rows.Count, "V").End(xlUp).Row

    Range("V11:V" & lrv).FormulaArray = _
        "=IFERROR(INDEX(Ftse!C[-4],MATCH(MAX(IF(RC[-21]=Ftse!C[-20],Ftse!C[-16])),IF(RC[-21]=Ftse!C[-20],Ftse!C[-16]),0)),0)"

    Range("V11:V" & lrv).Value = Range("V11:V" & lrv).Value

'   Find last row in column W with data
    lrw = Cells(Rows.Count, "W").End(xlUp).Row

    Range("W11:W" & lrw).FormulaArray = _
        "=IFERROR(INDEX(Ftse!C[-15],MATCH(MAX(IF(RC[-22]=Ftse!C[-21],Ftse!C[-17])),IF(RC[-22]=Ftse!C[-21],Ftse!C[-17]),0)),0)"

    Range("W11:W" & lrw).Value = Range("W11:W" & lrw).Value
    
'   Find last row in column X with data
    lrx = Cells(Rows.Count, "X").End(xlUp).Row

    Range("X11:X" & lrx).FormulaArray = _
        "=INDEX(Positions!C[-22],MATCH([@[FundID]],Positions!C[-16],0))"

    Range("X11:X" & lrx).Value = Range("X11:X" & lrx).Value

    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Sub
Note that you have to change the column you are using to determine the last row. If all three columns are supposed to end on the same line, then you really only need to find it once, and use that variable for all three.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top