VBA Formula Loop Question

tejadajm

New Member
Joined
Aug 21, 2002
Messages
10
I have the following code that works well. However, because of the size of my file, this loop takes a long time to run. Is there anyway to streamline what I am doing and perhaps calculate the formula in the VBA script and only return the value to the cell in Excel? Any help is greatly appreciated.



Sub Update_YPL()
For rwNumber = 6 To 55
For clNumber = 3 To 233
Cells(rwNumber, clNumber).Select

ActiveCell.FormulaR1C1 = _
"=IF(R4C="""","""",SUMIF(INDIRECT(""'""&R1C&""'!$C$1:$C$2000""),RC1,INDIRECT(""'""&R1C&""'!""&R4C&"":""&R4C)))"

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

Next clNumber
Next rwNumber
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try

Code:
Sub Update_YPL()
With Range(Cells(6, 3), Cells(55, 233))
    .FormulaR1C1 = "=IF(R4C="""","""",SUMIF(INDIRECT(""'""&R1C&""'!$C$1:$C$2000""),RC1,INDIRECT(""'""&R1C&""'!""&R4C&"":""&R4C)))"
    .Value = .Value
End With
End Sub
 
Upvote 0
You can do it without a loop

Code:
Dim MyRange as Range
Set MyRange = Range(Cells(6,3),Cells(55,233))
MyRange.FormulaR1C1 = "=IF(R4C="""","""",SUMIF(INDIRECT(""'""&R1C&""'!$C$1:$C$2000""),RC1,INDIRECT(""'""&R1C&""'!""&R4C&"":""&R4C)))"
MyRange.Copy
MyRange.PasteSpecial xlPasteValues

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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