Speeding up my code

RobbertH

Active Member
Joined
Apr 29, 2008
Messages
310
Hi guys,

I have a file in which, based on two criteria (=unique IDs), I like to paste comments that come from anonther worksheet in my file. The piece of code below does the trick but i **** slow. How can I tweak this in order to make it quicker?

Hope you can help!

Code:
Sub Paste comments()
Application.screenUpdating = False
For Each Cell In Range(Cells(2, 2), Cells(2, 2).End(xlDown))
    If Cell.Offset(0, 15) = 1 Then
        Cell.Offset(0, 14).FormulaR1C1 = "=IFERROR(INDEX('Standaard Verklaringen'!R1C2:R250C4,SUMPRODUCT(Match(" & Cell & "&" & Cell.Offset(0, 5).Value & ",'Standaard Verklaringen'!R1C2:R250C2&'Standaard Verklaringen'!R1C3:R250C3,0)),3),"""")"
        Cell.Offset(0, 14).Value = Cell.Offset(0, 14).Value
    End If
Next Cell
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
It seems to me that you are recalculating all open workbooks when you update each cell using "Cell.Offset(0, 14).FormulaR1C1" before then converting the result to 'values'.
I would try setting calculation to manual using 'Application.Calculation' and performing the loop twice. The first time to enter the formulas, then recalculate the worksheet before the second loop to convert the formulas to values. At the end reset the calculation mode back to what it was.
 
Upvote 0
Hi guys,

I have a file in which, based on two criteria (=unique IDs), I like to paste comments that come from anonther worksheet in my file. The piece of code below does the trick but i **** slow. How can I tweak this in order to make it quicker?

Hope you can help!

Code:
Sub Paste comments()
Application.screenUpdating = False
For Each Cell In Range(Cells(2, 2), Cells(2, 2).End(xlDown))
    If Cell.Offset(0, 15) = 1 Then
        Cell.Offset(0, 14).FormulaR1C1 = "=IFERROR(INDEX('Standaard Verklaringen'!R1C2:R250C4,SUMPRODUCT(Match(" & Cell & "&" & Cell.Offset(0, 5).Value & ",'Standaard Verklaringen'!R1C2:R250C2&'Standaard Verklaringen'!R1C3:R250C3,0)),3),"""")"
        Cell.Offset(0, 14).Value = Cell.Offset(0, 14).Value
    End If
Next Cell
Application.ScreenUpdating = True
End Sub

This may be more than a tweak, but maybe it can give you some ideas

Code:
Sub RobbertH()
Dim lr As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(3).Row
With Range("Q1:Q" & lr)

    .AutoFilter Field:=1, Criteria1:=1
    .SpecialCells(xlCellTypeVisible).Offset(0, -1).FormulaR1C1 = "=IFERROR(INDEX('Standaard Verklaringen'!R1C2:R250C4,SUMPRODUCT(Match("" & Cell & ""&"" & Cell.Offset(0, 5).Value & "",'Standaard Verklaringen'!R1C2:R250C2&'Standaard Verklaringen'!R1C3:R250C3,0)),3),"""")"
    .SpecialCells(xlCellTypeVisible).Offset(0, -1).Value = .SpecialCells(xlCellTypeVisible).Offset(0, -1).Value
    .AutoFilter
    .AutoFilter
    
End With
Range("P1").ClearContents
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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